You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For limited overloads length (for example 1 ~ 4), it can resolve with:
typeEmitEvent<F,E>=Fextends{(event: E, ...payload: infer P): infer R// match 'event n - 3'(...args: any): any(...args: any): any(...args: any): any} ? (...payload: P)=>R
: Fextends{(event: E, ...payload: infer P): infer R// match 'event n - 2'(...args: any): any(...args: any): any} ? (...payload: P)=>R
: Fextends{(event: E, ...payload: infer P): infer R// match 'event n - 1'(...args: any): any} ? (...payload: P)=>R
: Fextends{(event: E, ...payload: infer P): infer R// match 'event n'} ? (...payload: P)=>R
: unknow/* or `(...payload: any[]) => any` whatever */;// match 'event n < n - 3'
(Note: Increasing the number of overloads in this way inferred time will increase exponentially, so it is not feasible to detect the number of overloads dynamically generating EmitEvent<F, E>.)
Some libraries have more than 10 events overloads, so this is still a problem to be solved.
I spent a lot of time on this issue, and current TS version seems can't solve it.
Problem
Given a
$emit
type with unknow overloads length:How to get the event function type with specify event name?
What Now
For limited overloads length (for example 1 ~ 4), it can resolve with:
(Note: Increasing the number of overloads in this way inferred time will increase exponentially, so it is not feasible to detect the number of overloads dynamically generating EmitEvent<F, E>.)
Some libraries have more than 10 events overloads, so this is still a problem to be solved.
References:
The text was updated successfully, but these errors were encountered: