Web Developer

Basic TypeScript

  1. TypeScript could sign variables with different type, and after sign the type, you couldn’t assign other type of value to this variable, or errors will pop up. Syntax: let test: string, if you assign number to this variable, it will be errors.
  2. type of variable: :string, :number, :array<string>, :boolean, :any
  3. sometimes, TypeScript could infer the type of variable, in which it only happen when you declare variable and assign a value at the same time, if you don’t assign type to this variable, typescript will base on the value assigned to decide the type of the variable, and you can’t assign other type of value later.
  4. however, when you declare variable, if you don’t assign type to this variable, typescript will think the type of this variable is any, so you can assign any type of value to this variable later
  5. Class, first letter of class name should be capital letter. And in class should contain one constructor to run automatically when you create a new object with class. In class you can set up private property that can’t visit outside of the class, also you can set up static function, which could be visit anytime with Class name . method name
  6. Interface: like blue print, which can limit object have to include some properties, which could make user access these properties safely later
  7. Generics: Array<number>, which limits this array only could include number element

references: http://www.typescriptlang.org/Handbook

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>