#Wrong overload being chosen?

8 messages · Page 1 of 1 (latest)

celest cairn
#

Curious to why the hover tooltip shows the wrong overload being chosen? I would think the first argument would narrow the available overloads...

lean berryBOT
#
bestnameevercr#0

Preview:```ts
export function useEventListener<
T extends Document,
K extends keyof DocumentEventMap

(
observer: T,
...args: Parameters<
typeof document.addEventListener<K>

): void
export function useEventListener<
T extends Window,
K extends keyof WindowEventMap

(
obse
...```

sullen raft
#

Seems like it doesn't try to decide until you have enough args. Maybe that is a preliminary check, so it doesn't test until that is met

celest cairn
#

Hm. I think you're right. That's really quite annoying and some bad UX

#

I tried it with some random types and no .... Seems to behave similarly unfortunately

lean berryBOT
#
bestnameevercr#0

Preview:ts export function foo( arg0: string, arg1: number, arg2: boolean ): void export function foo( arg0: number, arg1: boolean, arg2: string ): void export function foo( arg0: boolean, arg1: string, arg2: number ): void export function foo(...args: any[ ...

lean berryBOT
#

@celest cairn Here's a shortened URL of your playground link! You can remove the full link from your message.

bestnameevercr#0

Preview:```ts
export function foo<T extends string | number | boolean>(
arg0: T,
arg1: T extends string ? number : T extends number ? boolean : string,
arg2: T extends string ? boolean : T extends number ? string : number,
): void {}

foo("", ```