TypeScript Interface for Array Type Example

This post shows how to use interface for Array types in TypeScript with an example.
In TypeScript, interfaces allow us to create contracts other classes/ objects have to implement. We can use them to define custom types without creating classes.

Read the complete tutorial at https://www.javaguides.net/2019/10/typescript-interface-tutorial-with-examples.html.

Interface for Array Type Example

An interface can also define the type of an array where you can define the type of index as well as values
interface NumList {

let numArr: NumList = [1, 2, 3];

// Array which return string
interface ProLangArray {

// use of the interface  
let progLangArray : ProLangArray = ['C', 'C++', 'Java', 'Python'];
[ 1, 2, 3 ]
[ 'C', 'C++', 'Java', 'Python' ]
Learn typescript at TypeScript Tutorial with Examples.


Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course