I'm trying to write a template function, that is an arrow function, and assign it to a const
variable,
This is supposed to be of the form const method: MethodType<T> = <T>(...) => { ... }
But it complains when I try to type the variable method
. Below is a snippet of the code:
export type KeyMethod<T> = (data: T) => any;
export interface DiffResult<T> {
additions: T[];
updates: T[];
deletes: T[];
};
export type DiffMethod<T> = (oldState: T[], newState: T[]) => DiffResult<T>;
it complains about this template
vvv
export const diffMethod: DiffMethod<T> = <T>(oldState: T[], newState: T[]) => {
return {
additions: [],
updates: [],
deletes: []
}
};
Is there any way to do this? maybe I'm failing to follow the syntax, but I haven't found a similar example for that.
As implied in a comment by Nitzan Tomer, you should write like the following.
export interface DiffResult<T> {
additions: T[];
updates: T[];
deletes: T[];
}
export type DiffMethod = <T>(oldState: T[], newState: T[]) => DiffResult<T>;
export const diffMethod: DiffMethod = <T>(oldState: T[], newState: T[]) => {
return {
additions: [],
updates: [],
deletes: []
};
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With