Consider this scenario involving conditional types:
type MyType = 'Number' | 'String';
interface Test<T extends MyType> {
bar: T extends 'Number' ? 25 : '25'
}
When attempting the following assignment:
const test: Test<'Number'> = {bar: null}
No errors are reported, indicating valid TypeScript syntax. However, hovering over bar
displays a tooltip stating
(property) Test<"Number">.bar: 25
, suggesting that TypeScript interprets the type correctly.
Why does the assignment not raise an error then? What steps can be taken to address this?