Skip to content

TS3.6/3.7 regression: template arguments used in unions no longer resolve/narrow #34754

Closed
@mprobst

Description

@mprobst

TypeScript Version: 3.7.1-rc

Search Terms: template argument union

Code

declare class Data {
  string<T>(defaultValue?: string|T): string|T;
}

declare const str: string|undefined;
const x = new Data().string(str);

Expected behavior:

I'd argue string, at least that's what the user intended here.

Actual behavior:

In TypeScript version:

  • 3.5, typeof x === string
  • 3.6, typeof x === unknown
  • 3.7, typeof x === string|undefined

Playground Link: n/a

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions