I'd like to pass variables into a template literal type value, but I can't seem to get it to work (you can play with the following example here). Is this possible?
type Bar = "a" | "b" interface Foo {label: `${Bar} (${number})`} const x: Foo = {label: "a (3)"}; // fine const myBar: Bar = "b"; const myNum: number = 3; const y: Foo = {label: `${myBar} (${myNum})`}; // errors
Is there any way of getting y
to compile?
没有评论:
发表评论