microsoft / microsoft/TypeScript
Incorrect conditional type evaluation on transformed function type expressions
Aperta
@weswigham ci sta già lavorando.
Dal 1/9/2023.
Needs Investigation
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
"conditional type", "function type", "extends", "evaluation", "inference"
🕗 Version & Regression Information
This is the behavior in every version I tried
⏯ Playground Link
💻 Code
// A extends B
type A = (value: string) => void
type B = (value: 'hello') => void
type FA = F<A>
// (value: string) => void
type FB = F<B>
// (value: 42) => void
// the computed values are compared correclty
type OK = FA extends FB ? true : false;
// return false
// the original expressions are not
type KO = F<A> extends F<B> ? true : false;
// return true
// This implementation does not exhibit the problem
type OO = G<A> extends G<B> ? true : false;
// return false
type F<T extends Fn> = (...args: TransformParams<Parameters<T>>) => ReturnType<T>
type G<T extends Fn> =
Parameters<T> extends infer Params extends unknown[]
? (...args: TransformParams<Params>) => ReturnType<T>
: never
type TransformParams<T> = { [K in keyof T]: K extends keyof [] ? T[K] : T[K] extends 'hello' ? 42 : T[K] };
type Fn = (...args: any[]) => unknown;
🙁 Actual behavior
The comparison of the expressions F<A> and F<B> is incorrect and is not equivalent to the comparison of their results.
🙂 Expected behavior
F<A> extends F<B> should be false because it should evaluate to ((value: string) => void) extends ((value: 42) => void), and string and 42 are unrelated.
Additional information about the issue
Interestingly, G, which should behave the same as F, does not exhibit the problem.
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.