Skip to content

Remove string literals from unions with matching template literals - #41276

Merged
Anders Hejlsberg (ahejlsberg) merged 3 commits into
masterfrom
stringAndTemplateLiteralUnions
Oct 27, 2020
Merged

Remove string literals from unions with matching template literals#41276
Anders Hejlsberg (ahejlsberg) merged 3 commits into
masterfrom
stringAndTemplateLiteralUnions

Conversation

@ahejlsberg

@ahejlsbergAnders Hejlsberg (ahejlsberg) commented Oct 27, 2020

Copy link
Copy Markdown
Member

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:

varx: '0';varx: '0'& `${number}`;vary: `${number}`;vary: `${number}` |'0';// Ok, previously was error

See also #40598.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@ahejlsberg@weswigham@andrewbranch@typescript-bot