Can't call 2 methods with the same signature with the same paramters

Viewed 37

I have written a type that helps me skip a parameter when the generic matches an empty object. A narrowed down example looks like following :

type SkipEmptyParameter<T> = {} extends T ? [] : [T];

declare function baz<T>(...[bar]: SkipEmptyParameter<T>): void;

baz<{}>()
baz<{ foo: 'test' }>({ foo: 'test' })

But I having trouble calling 2 functions with the same signatures & the same parameters :

function foo<T>(...[bar]: SkipEmptyParameter<T>): void {
    baz(bar);
}

// should behave like baz()
foo<{}>();
foo<{ foo: 'test' }>({ foo: 'test' })

I'm getting :

Argument of type '[T | undefined]' is not assignable to parameter of type 'SkipEmptyParameter<T | undefined>'

What's my mistake here ?

Playground

0 Answers
Related