TypeScript. Functions

Home » Tutorials » JavaScript » 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

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This