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
1// Parameter type annotation
2function greet(name: string): string {
3 return name.toUpperCase();
4}
5
6console.log(greet("hello")); // HELLO
7console.log(greet(1)); // error, name is typed (string)
1type return_type = ReturnType<() => string>; // string
2// or
3function hello_world(): string {
4 return "hello world";
5}
6type return_type = ReturnType<typeof hello_world>; // string
7
1// define your parameter's type inside the parenthesis
2// define your return type after the parenthesis
3
4function sayHello(name: string): string {
5 console.log(`Hello, ${name}`!);
6}
7
8sayHello('Bob'); // Hello, Bob!
1interface Date {
2 toString(): string;
3 setTime(time: number): number;
4 // ...
5}
6