Reputation: 5917
Given this example of conditional type:
type MyType = 'Number' | 'String';
interface Test<T extends MyType> {
bar: T extends 'Number' ? 25 : '25'
}
If I try to:
const test: Test<'Number'> = {bar: null}
I get no complains, this seems to be valid Typescript. However, when I hover over bar
I get a popup saying (property) Test<"Number">.bar: 25
which seems to mean that TS has understood the type correct.
Why do I get no error assigning in such a way then? How can I fix that?
Upvotes: 0
Views: 92