it's ok. <T>(T) => T is more common type and can receive any value.
how to fix error then?
not sure what are you trying to achieve but in this case a better way to describe Fn would be
type Fn<T> = (value: T) => T
let fn: Fn<string> = (s:string) => '2'
i want like so
type Fn = <T>(value: T) => T
function test(fn: Fn) {...}
test((s: string) => s)
test((s: number) => s)
type Fn<T> = (value: T) => T
function test<T>(fn: Fn<T>) {}
test((s: string) => s)
test((s: number) => s)
ok, thanks. Can it recognize automatically without generic here function test<T>(fn: Fn<T>)?
this is a question for @JSMonk
@Merciful12 is't incorrect case. Without generic in function test you can call function with any parameter:
type Fn = <T>(value: T) => T
function test(fn: Fn) {
fn(true)
}
test((s: string) => s)
test((s: number) => s)