Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove string literals from unions with matching template literals #41276

Merged
merged 3 commits into from
Oct 27, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

4 participants