⊗tsSpIfPp 20 of 37 menu

Interface Properties in TypeScript

Let's say we have an interface that describes a user:

interface IUser { }

Let's add properties and their type to this interface:

interface IUser { name: string; age: number; }

Now we create an interface object. To do this, we declare a variable in which we specify the selected interface as the type:

let user: IUser;

Now we can write values ​​for the properties defined in the interface:

let user: IUser = { name: 'john', age: 30 }

If we now try to create a user without setting the required properties, we will see an error:

let user: IUser = { name: 'john', // }

There will also be an error if you try to make an extra property:

let user: IUser = { name: 'john', surn: 'smit', // error age: 30 }

Create an interface IMath with properties num1 and num2.

Implement the calc object of the interface created above.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline