Using the TypeScript type checker to see if two types are assignable

后端 未结 2 1797
挽巷
挽巷 2021-01-18 16:04

I\'m building a small script that scans for all interfaces that have a member of a given type using the TypeScript Compiler API, of which the source can be found here. I ins

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 16:32

    Typescript is just a superset of JavaScript. You cannot make 'on the run' verifications with TypeScript that you are not able to do with Javascript.

    JavaScript does not have "classes" or "inherit" information. It only know creating objects and verify if an instance is instance of an object.

    JavaScript does have a method called 'instaceof' that verifies if a instance is instance of a class. for instance.

    var x = new ASTKind.Multiplication
    x instanceof ASTKind.Multiplication // will return true
    x instanceof AST // sill also return true
    

提交回复
热议问题