TypeScript Version: 2.7.0-dev.20171230
Code
function takeString(p: string) {}
function foo<T extends string | undefined>(param: T) {
takeString(param!); // error on this line
}
Expected behavior:
Because of the constraint the compiler knows the type of param can only be string | undefined. Asserting the type with a non-null assertion should result in string and the code should compile without error.
If this is working as intended, I'll write a lint rule to warn about non-null assertions on type parameters.
Actual behavior:
Argument of type 'T' is not assignable to parameter of type 'string'.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
TypeScript Version: 2.7.0-dev.20171230
Code
Expected behavior:
Because of the constraint the compiler knows the type of
paramcan only bestring | undefined. Asserting the type with a non-null assertion should result instringand the code should compile without error.If this is working as intended, I'll write a lint rule to warn about non-null assertions on type parameters.
Actual behavior: