If I have a function:
const flip = (A, B) => [B, A]
Add types to it:
const flip: <T1, T2>(A: T1, B: T2) => [T2, T1]
= <T1, T2>(A: T1, B: T2) => [B, A];
Then extract the type:
type FlipFunction<T1, T2> = (A: T1, B: T2) => [T2, T1];
How can I use this type for an arrow function (function expression)?
Unfortunately this errors:
export const flip: FlipFunction<T1, T2>
= <T1, T2>(A: T1, B: T2) => [B, A];
Cannot find name 'T1'.
As does this:
export const flip: <T1, T2>FlipFunction<T1, T2>
= <T1, T2>(A: T1, B: T2) => [B, A];
(' expected.
Using a function declaration unfortunately doesn't seem to be an option:
https://github.com/microsoft/TypeScript/issues/22063
edit: for the problem I'm trying to solve, the type FlipFunction above is already defined, but as an interface, that I can't change
e.g.
interface Component<C,T> extends ComponentBase<ComponentProps<C,T>>