I have the following code:
type Foo<T extends string = string> = `bar-${T}-foo`; const v: Foo = 'bar-g-foo' That works as expected, but it doesn't force the structure. The following is also valid:
const v: Foo = 'bar--foo' How can I force the usage of T?
type Foo<T extends string = string> = T extends "" ? never : `bar-${T}-foo`;would work (or perhaps without the default), but sadly, no. With the default, the type just ends up beingstring, and without the default, you have to explicitly provide the type parameter, and while doing that works, those aren't the ergonomics you want. :-|