I've been trying to make function overloads so my IDE could autocomplete the second paramater's type correctly based on the first argument's value. See example below:
class Animal {
constructor(private name: string) { }
bark(key: 'said', data: {
text: string;
}): void;
bark(key: 'barked', data: {
times: number;
}): void;
bark(key: 'said' | 'barked', data: any): void {
if (key === 'said') console.log(`${this.name} said ${data}`);
if (key === 'barked') for (let i = 0; i < data; i++) console.log('BARK!');
}
}
const barry = new Animal('Barry');
barry.bark('barked', {
/* Should auto-complete to { times: number } */
})
However the IDE autocompletes to both types for 'barked' and 'said'. See following example executed on Typescript sandbox
Am I typing it incorrectly? Or perhaps expecting something that is not supported? Thanks!

cakethe second would need to bemilk? It is an examplecake), the IDE should know the second parameter expects a type based oncakeand autocompletes it accordingly.