microsoft / microsoft/TypeScript
Generic type changes depending if its parameter type is wrapped or not.
@weswigham ci sta già lavorando.
Dal 5/12/2023.
- 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
💻 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.