is it posible to change the type of something based on the value of an argument passed to a function. I need this kind of type for an event emiter with callback. Example:
interface IUser {
name: string
}
type CallBack = /* the Type for the Callback that should be dynamic */
//for event1 the type CallBack should be (user: IUser) => any
use("event1", (user) => { /* check that event1 is used, so only add 1 argument to the callback type */ })
//for event2 the type CallBack should be (email: string, password: string) => any
use("event2", (email, password) => { /* check that event12is used, so add 2 argument to the callback type */ })
so is there a way to detect which event is used and apply the right type to the callback?