Arrays

Developed with
QA

Contents

keyboard_tab

The course is part of this learning path

Typescript: Zero to Hero
course-steps
8
certification
2
play-arrow
Arrays
Overview
DifficultyBeginner
Duration19m
Students118
Ratings
3/5
starstarstarstar-borderstar-border

Description

This module will introduce you to Simple Types in TypeScript. You’ll learn about Arrays, Tuples, and Type Assertion, too.

Learning Objectives

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

  • What Simple Types are
  • How to use Arrays
  • How to use Tuples
  • How to use Type Assertion

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

Arrays in TypeScript should be typed, and all element values in it should conform to the type specified. There are two ways TypeScript allows the defining of the type to be done as shown here. The first is to use the array JavaScript type, followed by angle brackets, that contain the type's name. That's shown on line seven. This notation will be familiar, if you've done any C# or Java programming. The second is to use the type name, followed by empty square brackets, as on line 11. Again, this will be familiar to some of you. When defining the values in the array, they should all follow the array's type. As you would expect, the length is not fixed, and adding and removing elements, using push, pop, shift, and unshift, are allowed. We've shown these executed on lines 14 to 17, and all other array functions, available in JavaScript, can be used too. If you try to push a non-numeric value to our number array, say a string, you should at the very least get an error on compilation, and, if you're using an IDE with TypeScript set up in it, like VS Code that we're using, you should get error notation. You can see that we get this on line 20, where we try and push a string. And it tells us that type five is not assignable to parameter of type number. But what would happen if this was compiled? And we ignored the errors? Well yes, you'd get the valid JavaScript that allows this behavior, but if you're expecting an array of numbers to process, and you get a string in the middle, then your application is potentially going to fall over at some point. It's worth noting that destructuring TypeScript arrays works in the same way as it does in JavaScript. But what about situations where we want mixed types in an array? Let's have a look at tuples.

Lectures

Simple Types: An Introduction - Tuples - Any and Unknown - Null and Unidentified - Function Arguments and Return Types - Enums - Type Assertion 

About the Author
Students4203
Labs8
Courses29
Learning paths6

Ed is an Outstanding Trainer in Software Development, with a passion for technology and its uses and holding more than 10 years’ experience.

Previous roles have included being a Delivery Manager, Trainer, ICT teacher, and Head of Department. Ed continues to develop existing and new courses, primarily in web design using: PHP, JavaScript, HTML, CSS, SQL, and OOP (Java), Programming Foundations (Python), and DevOps (Git, CI/CD, etc). Ed describes himself as practically minded, a quick learner, and a problem solver who pays great attention to detail. 

Ed’s specialist area is training in Emerging Technologies, within Web Development. Ed mainly delivers courses in JavaScript covering vanilla JS, ES2015+, TypeScript, Angular, and React (the latter is authored by Ed) and has delivered on behalf of Google for PWAs. Ed has also developed a new suite of PHP courses and has extensive experience with HTML/CSS and MySQL. 

Ed is responsible for delivering QA’s Programming Foundations course using the Eclipse IDE. His skillset extends into the DevOps sphere, where he is able to deliver courses based around Agile/Scrum practices, version control, and CI/CD.

Covered Topics