TypeScript Version: 3.1.4
Search Terms:
Code
function f<T extends boolean>(some: T = false) {}
Expected behavior:
TS would happily accept and type-check this code (leaving me solving type narrowing with guards later on)
Actual behavior:
Type 'true' is not assignable to type 'T'.
Playground Link: here is a link
Related Issues:
Duplicate of #21521
Nice catch @jack-williams, thanks!
It's not exactly a duplicate. I'm providing a constraint for T and expecting no need to do as T for the default value.
@DeTeam Yes you're right that it's not exactly the same, sorry about that. I think the reasoning will still be the same. You can get into situations like this:
f<true>();
I think this is a duplicate, or at least related: #28154
Yup, that one seem related.
We can close this one and continue in the original thread then :)
Most helpful comment
@DeTeam Yes you're right that it's not exactly the same, sorry about that. I think the reasoning will still be the same. You can get into situations like this:
I think this is a duplicate, or at least related: #28154