'How to use generic inside the function when typing with a type alias?
Let say I have a function like this(I know it is a nonsense):
const fn = <T>(a: number) => {
return a as unknown as Promise<T>
}
When I separate the type and the function with type alias like this:
type Fn = <T>(a: number) => Promise<T>
const fn: Fn = <T>(a) => {
return a as unknown as Promise<T>
}
I will get the following error:
Parameter 'a' implicitly has an 'any' type.
Why is that? How can I use generic when I type with type alias?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
