⊗jstsPmDSOAI 44 of 55 menu

Interface as an Object Type with a TypeScript Array

You can also specify an interface as the type for the entire object.

Let's look at an example. First, let's make an interface for the product:

interface Product { name: string, colors: string[] };

Then we create an object, specifying its type as the corresponding interface:

let prod: Product = { name: 'notebook', colors: ['red', 'black', 'gray'] }

Make a country object that contains the page title and an array of its cities.

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