Skip to content

typescript

  • used in build time, same as js for compile time
  • structure:
  • variables
  • object
  • union
  • aliases
  • query
  • class
  • generics
    • function of types

module

  • CommonJS(CJS)
  • require
  • module.exports
  • MJS(ES Modules)
  • import
  • export

Other options

HxqGdItest

casting

let temp = 2 as number

type

readonly

open interface

declare global {
  interface A {
    b: number;
  }
}

type query

keyof = object.keys typeof = get types of those values

function type

interface twonumbercalc { (a: number, b: number): number; }

const add: twonumbercalc = (a, b) => a + b;

void

  • used to indicate that a function does not return a value

this

setup type as parameter of function, also set strictBindCallApply to true in tsconfig.json

generic type

  • pass type as parameter to a type
  • dynamic type

record

  • obj's key and value

class

  • private
  • only can be accessed by this instance itself
  • can't be accessed by subclass
  • protected
  • can be accessed by subclass

return type