Riccardo Busin
Riccardo Busin

Reputation: 13

undefined / null get accepted as value for conditional type even if it shouldn't

Should't this throw a compiler error?

type Test<T extends number | string> = { v: T extends number ? true : false }
const test: Test<1> = { v: undefined }

Am I missing something?

Thanks

Upvotes: 1

Views: 22

Answers (1)

Karol Majewski
Karol Majewski

Reputation: 25790

It does if you have the strictNullChecks flag enabled in your tsconfig.json.

Playground

Upvotes: 2

Related Questions