hookex
11/26/2019 - 1:07 PM

Typescript

complie

in dir

tsc

specify dir

tsc -p {moduleDir}

option

specify module type

tsc --module <AMD | common.js | es2015>


interface MyFunc {
  (flag: bool):boolean
}

interface AllTypeInterface {
  myFun: MyFunc;
}

class 属性为什么需要提前生命

function logClass(target: any) {

  // save a reference to the original constructor
  let original = target;

  // a utility function to generate instances of a class
  function construct(constructor, args) {
    let c : any = function () {
      return constructor.apply(this, args);
    }
    c.prototype = constructor.prototype;
    return new c();
  }

  // the new constructor behaviour
  let f : any = function (...args) {
    console.log("New: " + original.name);
    return construct(original, args);
  }

  // copy prototype so intanceof operator still works
  f.prototype = original.prototype;

  // return new constructor (will override original)
  return f;
}