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

Properly union inferred template literal string types #46782

Merged
merged 5 commits into from Dec 6, 2021
Merged

Conversation

ahejlsberg
Copy link
Member

Fixes #46768.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for the StringMapping case also added seems relevant, but I can't even figure out how you'd use Uppercase in a nongeneric type and not have it evaporate (and thus see it in this code path), since, apparently Uppercase<`a${string}`> is `a${string}` right now (which seems like we could do better - something analogous to pattern types like `A${Uppercase<string>}` is what I'd want to see).

@ahejlsberg
Copy link
Member Author

@weswigham I added a couple of additional tests that include the StringMapping case. I agree it would be nice to do a little better on things like Uppercase<`a${string}`>, but it would require the compiler to have built-in knowledge of the semantics of those operations which I'm not totally crazy about.

@ahejlsberg ahejlsberg merged commit 2a7eb58 into main Dec 6, 2021
@ahejlsberg ahejlsberg deleted the fix46768 branch December 6, 2021 18:51
mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
* Template literals and string mappings have 'string' as base type

* Add regression test

* Add tests for generic template literals

* One more test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template literals not widening to a union type when spread as function parameters
4 participants