-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Milestone
Description
Bug Report
π Search Terms
typescript partial record key type checking failure
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common "Bugs" That Aren't Bugs"
β― Playground Link
π» Code
type MyKeyType = 'a' | 'b' | 'c';
type SubValuesType = {
values: string[];
};
type MyContainerType = {
badValues: Partial<Record<MyKeyType, SubValuesType>>;
};
function afunction(akey: MyKeyType){
let key = akey;
//key = 'c'; // uncomment me and assign any of a, b or c and compilation fails
const newData: MyContainerType = { badValues: { [key]: { anythingIWant: [] } } };
}
π Actual behavior
There is no type checking compilation error. I am able to assign an invalid type to newData
π Expected behavior
Checking error. At the very least I would call this a MASSIVE "principle of least surprise" failure. If this is the expected behaviour, it is extremely unintuitive.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created