Bug Report
When the template literal type is used in a union with strings that match its pattern, the union is reduced:
typeunion='downcast'|'dataDowncast'|'editingDowncast'| `${ string}Downcast`;// ^? type union = `${string}Downcast` | "downcast"This is a problem when I want to use it as a parameter type, because then only "downcast" is suggested when calling the function:
functiontest(groupName: union): void{}test('')// Only "downcast" is suggestedAs a workaround, I can use function overloading, where one signature has union with all string literals and another only the template literal type, but it would be nice to get this issue fixed:
functiontest2(groupName: 'downcast'|'dataDowncast'|'editingDowncast'): void;functiontest2(groupName: `${ string}Downcast` ): void;functiontest2(groupName: string): void{}test2('')// All "downcast", "dataDowncast" and "editingDowncast" are suggested🕗 Version & Regression Information
From 4.1 (when template literal types were introduced) to 5.1.0-beta, tested in TypeScript Playground.
⏯ Playground Link
Link to the TypeScript Playground
🙁 Actual behavior
Only string literals that don't match the template literal type are displayed.
🙂 Expected behavior
All string literals should be shown.
Bug Report
When the template literal type is used in a union with strings that match its pattern, the union is reduced:
This is a problem when I want to use it as a parameter type, because then only "downcast" is suggested when calling the function:
As a workaround, I can use function overloading, where one signature has union with all string literals and another only the template literal type, but it would be nice to get this issue fixed:
🕗 Version & Regression Information
From 4.1 (when template literal types were introduced) to 5.1.0-beta, tested in TypeScript Playground.
⏯ Playground Link
Link to the TypeScript Playground
🙁 Actual behavior
Only string literals that don't match the template literal type are displayed.
🙂 Expected behavior
All string literals should be shown.