Indexable Types

Developed with
QA

The course is part of this learning path

play-arrow
Start course
Overview
DifficultyBeginner
Duration9m
Students12

Description

This module introduces you to Interfaces in TypeScript.

Learning Objectives

The objectives of this module are to provide you with an understanding of:

  • How to use Function Types
  • How to use Optionals
  • How to use Excess Property Checks
  • How to use Indexable Types
  • How Interfaces work with Classes
  • How to create Extendable Interfaces

Intended Audience

This learning path is aimed at all who wish to learn how to use TypeScript

Prerequisites

It is essential you understand the face of contemporary web development to attend this course. You should have a good working knowledge of Javascript. Please note: Before attending this class delegates must have a Microsoft account (signing up one is free).

Feedback

We welcome all feedback and suggestions - please contact us at qa.elearningadmin@qa.com to let us know what you think.

Transcript

Similar to interfaces that describe function types, we can describe types we can index into. These indexable types have an index signature that describes the types we can use to index the object. Along with the corresponding types returned when indexing. The GarageArray1 interface specifies that each number index must have a string value. We define an array to implement a GarageArray1 interface. We can then access the string by using the array name and the index number. The GarageArray2 interface specifies that each index is a string and the value is a number. We define an array to implement the GarageArray2 to interface we can then access the number using the key. You can make index signatures read only to stop them being mutated. The third GarageArray demonstrates this with the interphase specifying read only and the error message when trying to reassign a key value.

Lectures

About the Author

Students1137
Labs8
Courses29
Learning paths5

An outstanding trainer in software development with more than 15 years experience as a Corporate and Apprentice Trainer, ICT Teacher and Head of Department, with a passion for technology and its uses. Continuing to develop existing and new skills and courses, primarily in web design using PHP, JavaScript, HTML, CSS and SQL but also OOP (Java), programming foundations (Using Python), DevOps (Git, CI/CD, etc) and Agile/Scrum. Practically minded, a quick learner and a problem solver with an attention to detail to ensure high quality outcomes.