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
{{ message }}
Repository navigation
Strict object literal check fails when infered to type containing string literal type #7085
when i compile using tsc (typescript@1.9.0-dev.20160215) i get a warning
test.ts(11,16): error TS2345: Argument of type '{ value: string; comparator: string; }' is not assignable to parameter of type 'Test'.
Types of property 'comparator' are incompatible.
Type 'string' is not assignable to type '"equals" | "isGreater"'.
Type 'string' is not assignable to type '"isGreater"'.
Apply a type annotation such as let tt: Test = { ... }. TS only infers string literal types in type positions and when contextually appropriate based on type information. Since TS doesn't do use-site analysis, tt gets typed soled by its definition, which is {value: string, comparator: string}, as there's no casts/annotations indicating it should use a literal type.
Activity
weswigham commentedon Feb 15, 2016
Apply a type annotation such as
let tt: Test = { ... }. TS only infers string literal types in type positions and when contextually appropriate based on type information. Since TS doesn't do use-site analysis,ttgets typed soled by its definition, which is{value: string, comparator: string}, as there's no casts/annotations indicating it should use a literal type.