I have successfully created a function that eliminates the 'Bar' at the end of a string when using foo
. However, is there a way to achieve the same result using the type
statement? (refer to the code snippet below)
declare function foo<T extends string>(str: `${T}Bar`): T;
const justFoo = foo('fooBar');
// justFoo now has the type 'foo'
// How can we accomplish this?
type Foo<T extends string> = T;
type JustFoo = Foo<'fooBar'>;