Is it feasible to alter the type of something depending on the value of an argument passed to a function? I am in need of this specific type for an event emitter with callback. For instance:
interface IUser {
name: string
}
type CallbackType = /* A dynamic Type for the Callback */
// Type for CallBack should be (user: IUser) => any when used for event1
use("event1", (user) => { /* Verify that event1 is utilized, and add only 1 argument to the callback type */ })
// Type for CallBack should be (email: string, password: string) => any when used for event2
use("event2", (email, password) => { /* Confirm that event2 is utilized, and include 2 arguments in the callback type */ })
Therefore, is there a method to determine which event is being used and assign the appropriate type to the callback?