I have this type:
type EventCallback<T> = (ev: T, anotherParam: string, lastParam: string) => void;
And this interface:
interface CustomEvent {
...
payload: any;
}
And this arbitrary class:
class ArbitraryClass {
methodOnArbitraryClass() {
// do stuff
}
}
I then create functions of this shape:
const exampleCallback: EventCallback<CustomEvent> = (ev: { payload: CustomEvent }, anotherParam: "foo", lastParam: "bar") => {
// handle event
};
All good.
Now I want to add a parameter to callbacks of this shape, without changing the return type, and while still using the EventCallback<CustomEvent>
, say we call this type DesiredCallback
, such that:
const newExampleCallback: DesiredCallback = (newParam: ArbitraryClass, ev: { payload: CustomEvent }, anotherParam: "foo", lastParam: "bar) => {
// handle event
};
I am looking for a way to define the DesiredCallback
type by extending the EventCallback
type, which means only defining the new parameter(s), and leaving the parent EventCallback
type responsible for defining the other parameters, which the DesiredCallback
type inherits.
I would be fine with the newParam
parameter being ordered anywhere in the positional parameter list (beginning or end).