Skip to content

Intersections with template literal types not correctly reduced #41161

@ahejlsberg

Description

@ahejlsberg

TypeScript Version: 4.1.0-dev

In #40598 we added logic to reduce intersections of string literal types and template literal types. This logic incorrectly produces single-element intersections instead of reducing to the single constituent type. This means that '0' and `'0' & `${number}` are not considered identical--even though they display as the same type!

Code

var x: '0';
var x: '0' & `${number}`;  // Error: 'x' must be of type '"0"', but here has type '"0"'

Expected behavior:

No error.

Actual behavior:

Error as shown above.

Playground Link:

https://www.typescriptlang.org/play?ts=4.1.0-dev.20201015#code/G4QwTgBAHgXBDkAGeBuAUKSsHIgMggAMASAbwDsBXAWwCMBTMAX0JQggHoOIBRMMAPZg48KPAjVKAZwAuEBhAEAzCDICeAB3oIARIh3wANPMpyAFo21mQU1Zu3w9BtEA

Related Issues: #40598

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions