Let's say we have code like this:
interface Vehicle {
bicycle(): string;
car(wheel: number): void;
bus(passanger: number): {
name: string;
age: number;
}[];
}
type Mapper<K extends keyof Vehicle> = (funcName: K, callback: Vehicle[K]) => void;
interface MapperB {
<K extends keyof Vehicle>(name: K, callback: Vehicle[K]): any;
}
declare const caller: Mapper<keyof Vehicle>;
declare const callerB: MapperB
Or typescript playground here.
And when i call caller and callerB, caller can't infer the callback type according to the first argument. Actually, I found that there is no way to archive that. But callerB just does everythings well.
caller("bicycle", () => {
})// can't give any intellisense
callerB('bus', (passanger) => {
return [{
name: 'Jack',
age: 11
}]
})// will give perfect hints according to first argument.
So I was wondering what's the difference between those two declaration, it doesn't seems to be a bug.