1interface Safer_Easy_Fix {
2 title: string;
3 callback: () => void;
4}
5interface Alternate_Syntax_4_Safer_Easy_Fix {
6 title: string;
7 callback(): void;
8}
9
1function createPerson(name: string, doAction: () => void): void {
2 console.log(`Hi, my name is ${name}.`);
3 doAction(); // doAction as a function parameter.
4}
5
6// Hi, my name is Bob.
7// performs doAction which is waveHands function.
8createPerson('Bob', waveHands());
1interface Alternate_Syntax_4_Advanced {
2 title: string;
3 callback<T extends unknown[], R = unknown>(...args?: T): R;
4}
5
1interface Better_still_safe_but_way_more_flexible_fix {
2 title: string;
3 callback: <T = unknown, R = unknown>(args?: T) => R;
4}
5interface Alternate_Syntax_4_Better_still_safe_but_way_more_flexible_fix {
6 title: string;
7 callback<T = unknown, R = unknown>(args?: T): R;
8}
9