TypeScript

  • TypeScript is a superset of JavaScript that supports the ECMAScript 6 standard.
  • TypeScript is designed for large applications that can be compiled into pure JavaScript that runs in any browser.

The TypeScript object

www.runoob.com/typescript/…

TypeScript type templates

Var sites = {site1: "Runoob", site2: "Google", sayHello: function () {} // type template}; sites.sayHello = function () { console.log("hello " + sites.site1); }; sites.sayHello();Copy the code

An object can also be passed to a function as an argument.

var sites = { 
    site1:"Runoob", 
    site2:"Google",
}; 
var invokesites = function(obj: { site1:string, site2 :string }) { 
    console.log("site1 :"+obj.site1) 
    console.log("site2 :"+obj.site2) 
} 
invokesites(sites)
Copy the code

type

Indicate the type

  1. The explicit declaration

let a: string; Let a =12;

If you “let variables hold anything”

  1. No initial value is given
  2. The explicit declarationany
  • number/string/boolean/any

(Type 1 | Type 2 | Type 3)

  • Tuple type [type 1, type 2]
  • Enumeration: Enumerate limited possibilities
  • Void: Often used to return values
  • null/undefined
  • never

Class (new writing)

  • Access modifier

Public: anyone can modify it. Private: Protected only inside a class: protected only classes and subclasses

  • How do I use access modifiers?

“Minimum access rule” “Properties are private protected, methods can be public”

  • The modifier

Static: a static member that can be called without instantiation const: a read-only member that cannot be modified

  • accessor

Set /get: failed to compile ES3/ES4

Advanced features (abstractions, interfaces)

Some objects have common characteristics:

  1. inheritance
  2. Implementing an interface

Abstract class: can only be used as parent and cannot be instantiated directly. Only provide the template, not their own implementation. (Standardize all subclasses)

conclusion

  1. type
  2. Modifiers (access modifiers)
  3. The generic
  4. Abstract classes & interfaces