-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
"mapped type" "record" "enum"
π Version & Regression Information
- This issue can be produced in versions >= 5.8.3 (Don't test lower versions)
β― Playground Link
π» Code
function testFuncWithRecordReturn(): Record<string, string> {
return {};
}
const testRecord = testFuncWithRecordReturn();
const testEnumObj = {
A: 'QWE_A',
B: 'QWE_B'
} as const;
type TestEnumObj = typeof testEnumObj[keyof typeof testEnumObj];
function testWithObjEnums(test: Record<TestEnumObj, string>): string {
return test.QWE_A;
}
function testWithObjMapEnums(test: { [Key in TestEnumObj]: string }): string {
return test.QWE_A;
}
const test1 = testWithObjEnums(testRecord); // Not fail but must
const test1_1 = testWithObjMapEnums(testRecord); // Fail and it's correct
enum TestEnum {
A = 'QWE_A',
B = 'QWE_B'
}
function testWithEnums(test: Record<TestEnum, string>): string {
return test.QWE_A;
}
const test2 = testWithEnums(testRecord); // Also must failπ Actual behavior
Typescript does not fail in places with specific keys objects
π Expected behavior
Typescript must shows an errors in commented places with same error as the correct one
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created