Allow concatenated strings to be cast as const type #54161
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Suggestion
π Search Terms
Concatenated strings const type
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Allow
as const
cast to be applied to concatenated string literals like so:https://www.typescriptlang.org/play?#code/FAehAIGcAZwdwPYFcA2ATcAjApuA5AIaZ7ADGCAdpAC5SwC84AFIXuANT7ECU4Bk4clWoBuYKAiQAjOACWAwsTKUaUGY0Vt+glaKA
π Motivating Example
It's convenient to split a long string into multiple concatenated lines to enhance code readability, so
as const
cast should work for it as well.π» Use Cases
Currently only a single string is allowed to be cast to its literal type. So as a workaround you just sacrifice code readability and make multiple strings into one:
'a' + 'b' => 'ab'
The text was updated successfully, but these errors were encountered: