Skip to content

non-null assertion on TypeParameter changes string | undefined to String #21360

Closed
@ajafff

Description

@ajafff

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions