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

@ahejlsberg Anders 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:

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

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

See also #40598.

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.

4 participants