microsoft / microsoft/TypeScript
Type inference does not work for enums and calculated props
Aperta
@weswigham ci sta già lavorando.
Dal 8/12/2018.
Bug
Domain: check: Type Inference
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
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.