Skip to content

5.1.3 new "feature"? Branded types are preserved in const template literalΒ #54648

Closed

Description

Bug Report

πŸ”Ž Search Terms

branded, interpolation, 5.1.3

πŸ•— Version & Regression Information

This changed between versions 5.0.4 and 5.1.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type S = `id_${string & {_brand: "ID"}}`;
//   ^? type S = `id_${string & { _brand: "ID"; }}`
declare const id: string & {_brand: "ID"};
const s = `id_${id}` as const;
//    ^? const s: `id_${string & { _brand: "ID"; }}`

πŸ™ Actual behavior

The intersected brand is preserved during string interpolation for variables and types!

πŸ™‚ Expected behavior

Pre 5.1.3, the intersected brand always got removed during string interpolation for variables and types.

This is part bug report and question. My question being in future versions, will this behavior be preserved? I wrote a clunky generic function and type to do this exact thing because I found it valuable, but I'd much rather rely on native behavior if this is going to stick around πŸ‘€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions