-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 2.5.2
Code
function ifnull<T>(x: T | null | undefined, def: T): T
{
return x != null ? x : def;
}
ifnull(2, 1);Expected behavior:
The inferred type for T should not depend on strictNullChecks.
Actual behavior:
It is number when used without strictNullChecks, but it is the type 1 when used with strictNullChecks.
I understand you don't want to infer the intersection type 1 | 2, but I think it will be more useful to infer the type number. Many generic functions accept two arguments of the same type (two numbers, two strings, etc.), but when you call it with different values Typescript (with strictNullChecks) will always issue an error because it will infer the incompatible types value1 and value2 for T.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed