-
Notifications
You must be signed in to change notification settings - Fork 13.3k
non-null assertion on TypeParameter changes string | undefined to String #21360
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.7.0-dev.20180123
Search Terms:
Code
declare function foo(p: string): void;
function fn<T extends string | undefined, U extends string>(one: T,two: U) {
let three = Boolean() ? one : two;
foo(one!);
foo(two!);
foo(three!); // error on this line
}Expected behavior:
No type error.
Actual behavior:
Argument of type 'string | String' is not assignable to parameter of type 'string'.
Type 'String' is not assignable to type 'string'.
'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
This is caused by #20995. To be fair, without that change the above was not valid at all.
Playground Link:
Related Issues:
Maybe related to #21317
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue