My problem is basically perfectly encapsulated in this playground
You can also read the code here:
function foo<T extends number | string = string, U extends string = string>(name: U): U {
return name
}
const bar = foo("hello")
// ^? const bar: "hello"
// I want `U` to still be inferred as a string literal,
// even though I just explicitly gave the first generic type argument
const baz = foo<number>("bye!")
// ^? const baz: string
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.