Branded string literals revert to string
in some cases
#60990
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
🔎 Search Terms
If I create a branded string literal it seems to respect the string literal in the basic case of assigning to a property, however it loses this information and just reverts to string when assigning to a property or in a template string.
It makes sense that the brand object needs to be dropped in these cases, but rather than converting to string, it should convert to the narrower literal type.
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAsiAyBLYEBOBDANgHgMpQgA8UA7AEwGcoLhVESBzAPigF4p8AyKAbwH0ARhnIAuXgF9xAbgBQAYwD2JGlHRsoAcnQbVVOEhQYcWjU1nylKwmJPr0UqAHpHUAO4LUAawoBCC8uAoEBttdQADABIedHEwh2coADN0RExffxUALzFosRIAVwBbATRxdR4AbXQAXTEADjKE5NTfIA
💻 Code
🙁 Actual behavior
For
y
andz
, the types don't match becausea
is converted tostring
rather than'a'
🙂 Expected behavior
The types should match in all 3 cases,
x
,y
,z
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: