microsoft / microsoft/TypeScript
Type inference does not work for enums and calculated props
Offen
@weswigham arbeitet bereits daran.
Seit 08.12.2018.
Bug
Domain: check: Type Inference
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 3.1.6
Calculated props, Spread operator, Enum keyed types
Code
enum Test {
param = 'X',
other = 'Y',
last = 'Z',
};
type TSomeOtherType = {
readonly someProp: number;
readonly orOther: string;
};
type TKeyedByEnum = {
[key in Test]: TSomeOtherType | null;
};
// const throwsCompilerError: TKeyedByEnum = {
// [Test.param]: 123,
// };
Object.keys(Test).reduce(
(acc, key: Test): TKeyedByEnum => {
const doesntThrow: TKeyedByEnum = {
...acc,
[key]: 123,
};
return doesntThrow;
},
{} as TKeyedByEnum
);
Expected behavior:
Typescript compiler throws an error on the object doesntThrow.
Actual behavior:
There is no typescript error on the object doesntThrow. The resulting object of type TKeyedByEnum contains values of type number.
Related Issues:
https://github.com/Microsoft/TypeScript/issues/27704
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.