June 2025
Intermediate to advanced
837 pages
24h 50m
English
TypeScript interfaces are structures that don’t have method implementations and can’t be instantiated. However, like classes, they represent separate types you can use for variables and function signatures. Listing 13.25 shows an example of using such an interface.
class Movie { constructor( public id: number, public title: string, public year: number ) {}} interface WithTitle { title: string;} function show(movie: WithTitle) { console.log('Now showing: ', movie.title);} const infinityWar = new Movie(3, 'Avengers: Infinity War', 2018); show(infinityWar); // Output: Now showing: Avengers: Infinity War
Listing 13.25 Inline Interfaces with TypeScript
As you can see here, you can use the interface at any point where you ...
Read now
Unlock full access