microsoft / microsoft/TypeScript
Inferring less information for generics in 4.2+ compared to previous versions
Offen
@weswigham arbeitet bereits daran.
Seit 17.8.2021.
Needs Investigation
Rescheduled
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.