Support inferred string-modified union types #17512
Labels
Domain: Literal Types
Unit types including string literal types, numeric literal types, Boolean literals, null, undefined
Suggestion
An idea for TypeScript
Too Complex
An issue which adding support for may be too complex for the value it adds
I ran into an interesting situation that I wanted to run by the community to see if there's a way to add a new feature into TypeScript to support. I'll grant that it's an edge-case, but it seems like something that could be kind of neat.
Here's the code:
Code
I think it would be neat if the expression:
could be automatically inferred to be of type:
It's probably a lot more complex than it seems. And there's probably a heck of a lot of issues dealing with what happens with other string operations or if a runtime function like .toUpperCase() is called on the string, and what happens if any item in the union isn't a string, etc, etc. But still.
Any thoughts?
The text was updated successfully, but these errors were encountered: