So I am trying to make it so bind event receives an object of type BoundEventTarget<ObjectType,ObjectEventsType> and allow the function to infer the event names and their corresponding callbacks. that part works and while I can use "on" and "off" once I have filled in "ObjectType" it does not work when I try to use "on" inside the "bindEvent" function.
Here is the code
#Generics issue
22 messages · Page 1 of 1 (latest)
Preview:```ts
export type Awaitable<T> = T | Promise<T>
export type BoundEventCallback<
T extends
| ((...args: any[]) => Awaitable<void>)
| any[]
= T extends any[]
? (...args: T) => Awaitable<void>
: T
export type TargetEvents = {
[
key: string | symbol | number
]: BoundEventCallback<any
...```
You can choose specific lines to embed by selecting them before copying the link.
Generics issue
Preview:```ts
export type Awaitable<T> = T | Promise<T>
export type BoundEventCallback<
T extends
| ((...args: any[]) => Awaitable<void>)
| any[]
= T extends any[]
? (...args: T) => Awaitable<void>
: T
export type TargetEvents = {
[
key: string | symbol | number
]: BoundEventCallback<any
...```
You can choose specific lines to embed by selecting them before copying the link.
yes
I replaced it with {}
hm
which is more correct I think?
In any case don't use any, use unknown and never instead
thanks
any is really only meant to deal with completely untyped JS code