Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Oct 27, 2020

We currently remove template literals from intersections containing matching string literals. For example `foo${string}` & 'foox' is reduced to just 'foox'. We also need to perform the complementary reduction for union types, i.e. `foo${string}` | 'foox' should reduce to just `foo${string}`. This PR adds that functionality.

The following now produces no errors:

var x: '0';
var x: '0' & `${number}`;

var y: `${number}`;
var y: `${number}` | '0';  // Ok, previously was error

See also #40598.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 27, 2020
@ahejlsberg ahejlsberg added this to the TypeScript 4.1.1 milestone Oct 27, 2020
@ahejlsberg ahejlsberg merged commit 40b8122 into master Oct 27, 2020
@ahejlsberg ahejlsberg deleted the stringAndTemplateLiteralUnions branch October 27, 2020 23:21
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants