microsoft / microsoft/TypeScript

Generic type changes depending if its parameter type is wrapped or not.

Aperta
#56,675 3 commenti 1 reazione 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 5/12/2023.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

generic type bug

🕗 Version & Regression Information

latest version as of today.

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAkgZjAJhAdsAlgYwIYBsA8AGgDRQCapAglALxTABOArhKQEK1Rx4DOEAfLQBQUUVAAU+ACr9xASlqCpUCAA9gqRDyiEoAfigBGKAC4oAJgVqNKLSLGSZ8xVGXXN2svqOmLCg9RmbADcQmGgkLBwAPIM+AAKpACKpFLM0HSMLKQAYrwZXPmCdPBIqBg4BImFuHykpchoWHj4KTV1UHm1rK7p-Kl9oUIR0AD6xiUxcVk9M-zBUAD0i-Tpw+Bj5pzwsfgzpNzd80srM+uRowDM21P4hx1zC8urLOdjACw3u-c9P8fPPzCb1gPAAyox0CgAObSYpRMpNSrSUg8CHQ+bhDZQUYAVm2YLRMJQTAAtgAjCAMDFAkbYqQQVETKLffL1AkMSFE0kUqn-FY-AB0UEwAHsGAwIJhgABCIHAnYMADq6GAAAt4OCOdDYV84j82ZrObDqbTRvTUVtJrFlWqNYT8MTyZS+S8IAYyUwobKgA

💻 Code
type IfIdentical<X, Y, A = true, B = false> =
    (<T>() => T extends X ? 1 : 2) extends
    (<T>() => T extends Y ? 1 : 2) ? A : B;


type IfOr<P, Q, True = true, False = false> = IfIdentical<P, false, IfIdentical<Q, false, False, True>, True>;

type _1 = IfOr<true, true>; // true
type _2 = IfOr<true, false>; // true
type _3 = IfOr<false, true>; // true
type _4 = IfOr<false, false>; // false


type IsString<T> = IfIdentical<T, string>;

type _5 = IsString<number>;



type _Test1 = IfOr<false, IsString<number>>; // false. correct!



type IfOrWithIfString<T> = IfOr<false, IsString<T>>;

type _Test2 = IfOrWithIfString<number>; // true? bug!
🙁 Actual behavior

types _Test1 and _Test2 are different even though they are calculated the same way.

🙂 Expected behavior

types _Test1 and _Test2 should be the same.

Additional information about the issue

Not sure if it's the best minimal reproduction, because it's difficult to pinpoint the actual problem.
The example is based on the a type suggested by Matt McCutchen here, but I can't tell if the issue is unique to that type or if it happens in other scenarios.

Based on that IsEqual type I created a "if or" type IfOr<P, Q> and a "is string" type IsString<T>.

The difference between _Test1 and _Test2 is that the first passes IsString<number> result (false) directly to IfOr, while the second passes number to an intermediary type, sort of wrapping the IsString.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.