Basics
Challenges
Classes
Debugging
Events
External Files
Flow Control
Forms
Functions
Html Elements
Installation
Interfaces
Keywords
Modules
Namespaces
Operators
Reference Files
String
Types
as: Use the as
keyword to give an exported class an alias.
You can export ClassA
as ClassB
and it will appear as ClassB
in the classes in which import into.
export Employee as StaffMember;
const: Values cannot be changed once they are bound.
A const
can be used anywhere.
const secretCode: string = "abc";
export: Allows you to convert and encapsulate your code into a "module" making it available to other ts code which will them import it. Very much like namespaces.
export class Spaceship{}
Extends: Used with Abstract Classes and derived Classes.
A derived Class extends
an abstract
class.
class Dog extends Animal
Implements: Used with Interfaces and Classes. A Class implements
a interface
.
class Employee implements IPerson
readonly
: A keyword that can only be used in a class.
let readonly _secretCode: string = "abc";
super: Each derived class that contains a constructor function must call super() which will execute the constructor of the base class.
class WebDeveloper extends Developer
{
favoriteEditor: string;
constructor(editor: string)
{
super();
this.favoriteEditor = editor;
}
}
Each derived class that contains a constructor function must call super() which will execute the constructor of the base class . What’s more, before we ever access a property on this in a constructor body, we have to call super(). This is an important rule that TypeScript will enforce.