Skip to content

Instantly share code, notes, and snippets.

@davidrapin
Created November 21, 2016 16:48
Show Gist options
  • Save davidrapin/473e4e5bd76ac3ec01b33fa03f0146c7 to your computer and use it in GitHub Desktop.
Save davidrapin/473e4e5bd76ac3ec01b33fa03f0146c7 to your computer and use it in GitHub Desktop.
store TypeScript type metadata for runtime check

sauce

You should be able to use the TypeChecker API from the compiler to get to the type information you need. there is no serialization logic readily available, but should be possible to add one.

Here is the TypeChecker API: https://github.com/Microsoft/TypeScript/blob/085f0df4556801c14a4333d6c1d0bab1375586e4/lib/typescript.d.ts#L1027-L1057

Documentation on using the compiler API: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

Here is the part of the emitter that emitts this infromation today using the Checker: https://github.com/Microsoft/TypeScript/blob/085f0df4556801c14a4333d6c1d0bab1375586e4/src/compiler/emitter.ts#L5065-L5104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment