Hi,
Consider the follow code:
type AsyncFunction<Param, Result> = (p: Param) => Promise<Result>
function createAsyncWithCallback<Param, Result>(fn: AsyncFunction<Param, Result>) {
return fn
}
function fnWithParams(params: string) {
return Promise.resolve(params)
}
function fnWithoutParams() {
return Promise.resolve(null)
}
const fn1 = createAsyncWithCallback(fnWithParams);
const fn2 = createAsyncWithCallback(fnWithoutParams);
fn1("param")
fn2("any-param")
I would have thought that creating fn2 shouldn't work because the callback does not have any params and I have defined my generic type to only allow callbacks with params.
Any ideas? -- thanks