TypeScript. Functions
In this video we’ll consider new features in functions work and union types in TypeScript.
Code lesson
interface Football {
cloth: string;
score: string;
getSportName: () => 'Football';
getFootballString: () => 'Football string';
}
interface Hockey {
cloth: string;
score: string;
getSportName: () => 'Hokey';
getHockeyString: () => 'Hockey string';
}
function func(): Football | Hockey {
// code
}
let sport = func();
sport.getSportName();
// sport.getFootballString();
if((<Football>sport).getFootballString) {
(<Football>sport).getFootballString();
}
0 Comments