You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeUnionType="ABC"|"XYZ"typeRecordType=Partial<Record<UnionType,string>>// no errors, okconstvalue1: RecordType={XYZ: "some value",}// error, ok, number where string is expectedconstvalue2: RecordType={XYZ: 123,}// error, ok, number where string is expectedconstvalue3: RecordType={["XYZ"]: 123}// error, ok, key test is not allowedconstvalue5: RecordType={["test"]: 123}// as UnionType clause is important// it could be a function that returns UnionType, e.g. const key = getUnionKey(), same problemconstkey: UnionType="XYZ"asUnionType// no error, but it should be thereconstvalue4: RecordType={[key]: 123}
π Actual behavior
No error when using square brackets. Last example.
π Expected behavior
It should throw an error.
The text was updated successfully, but these errors were encountered:
Bug Report
Under certain conditions typescript compiler allows setting any value for a record that has union type key. See code section below.
π Version & Regression Information
Tested in 4.8.4
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
No error when using square brackets. Last example.
π Expected behavior
It should throw an error.
The text was updated successfully, but these errors were encountered: