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

Typescript: Zero to Hero
course-steps
8
certification
2
play-arrow
Start course
Overview
Difficulty
Beginner
Duration
13m
Students
151
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
Avatar
Ed Wright
Senior Learning Consultant
Students
7041
Labs
7
Courses
29
Learning Paths
7

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