Imagine having a function with intricate types
function torgle<
A extends string,
B extends number,
Flurg extends string = `[${A}]<>[${B}]`
>(flurg: Flurg): string {
return `hello, ${String(flurg).replace(/[[\]<>]/g, '')}`
}
Usually, the type Flurg
is not predefined, so it's easier to let torgle
create it:
torgle<'blue', 32>('[blue]<>[32]')
hello, blue32
However, there are times when I have a custom Flurg
type and want to pass it in myself:
>> torgle<'_unused', '_unused', 'cheeseburger'>('cheeseburger')
hello, cheeseburger
In such cases, having A
and
B</code becomes unnecessary. It would be more efficient to have a variant of <code>torgle
where they are not obligatory:
function torgle<Flurg extends string>(flurg: Flurg) { ... }
Refer to this CodeSandbox example.
Is there a way to mix these two versions of torgle
, or do I need separate functions like torgle1
and torgle2
?