Structural Typing

Developed with
QA

Contents

keyboard_tab
Typescript
1
Inheritance
PREVIEW1m 24s
2
Access Modifiers
PREVIEW4m 17s
4
Abstracts
1m 52s

The course is part of this learning path

play-arrow
Start course
Overview
DifficultyBeginner
Duration13m
Students15
Ratings
5/5
starstarstarstarstar

Description

This module introduces you to Classes and how to use them in TypeScript.

Learning Objectives

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

  • What classes are
  • How to use inheritance in TypeScript Classes
  • How to use Access Modifiers
  • How to use Abstracts
  • How to use Structural Typing

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

TypeScript is a structural type system. If the types of all members are compatible, then the types are compatible, this except for private and protected members. It's also known as duck-typing, coming from the phrase, if it waddles like a duck and quacks like a duck, then it's a duck. And we'll demonstrate what we mean by this through the code. We declare a class STVehicle that has public properties, wheels and power. The class STCar extends STVehicle and called super in its constructor. A third class STTaxi is standalone and has public properties, wheels and power. On line 28 and below, we declare some instances of the car, taxi and vehicle. Through inheritance it's possible and logical that we can make my STVehicle, an instance of an STCar class. It's just how the, is a part of inheritance works. But what about an STTaxi? Could we set our instance of the STVehicle class to an instance of the STTaxi class? Yes, check line 41 on the top of the right to the screen. According to the structural typing rules, two objects are considered to be the same type, if both share the same set of properties, the STTaxi class is defined with the same properties and access modifiers as the STVehicle class. If it waddles like a duck and quacks like a duck, then it's a duck. We define another class on line 46. That's the same property names as the STVehicle class, but the typing and the access modifiers a slightly different. We create an instance of the Rikshaw class and try and set it to the value for the instance of the STVehicle class. And there's an error because the Rikshaw type is not assignable, to the STVehicle type. But what would happen if we compiled ignoring this? Now remember the only lesson we need, my STVehicle would log out as the ritual. So in this module, we've examined how classes are implemented in TypeScript paying particular attention to access modifies, including static, getters, and setters, abstract classes and functions, and how structural types apply to classes. It would be good to go and do some practice with the syntax and concepts now.

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.