-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
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'.
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript