microsoft / microsoft/TypeScript
Inferring less information for generics in 4.2+ compared to previous versions
@weswigham ci sta già lavorando.
Dal 17/8/2021.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
infer used as the value of a generic no longer infers the actual value, but it infers the default value of that generic argument.
🔎 Search Terms
infer, unknown, default, generic
possibly similar issues?
https://github.com/microsoft/TypeScript/issues/43161
https://github.com/microsoft/TypeScript/issues/42939
🕗 Version & Regression Information
- This changed between versions 4.1.5 and 4.2.3
⏯ Playground Link
Playground link with relevant code in 4.2.3
Playground link with relevant code in 4.1.5
💻 Code
type Shape = {
key: Record<string, unknown>;
};
type ShapeCreator<T extends Shape> = (cb: (state: T['key']) => void) => void;
type ExtractShape<T> = T extends ShapeCreator<infer TShape> ? TShape : never;
type StateShape = {
key: { letter: string };
};
type StateShapeCreator = ShapeCreator<StateShape>;
const wrongShape: ExtractShape<StateShapeCreator> = {
key: {
// @ts-expect-error
letter: 2,
},
};
🙁 Actual behavior
the inferred value is the default of the generic
🙂 Expected behavior
the inferred value is the actual value of the generic, like it used to do.
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.