microsoft / microsoft/TypeScript
Type inference does not work for enums and calculated props
オープン
@weswigham がすでに取り組んでいます。
2018年12月8日 から。
Bug
Domain: check: Type Inference
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。