Introduction to generating TypeScript definition files from JavaScript code. The demo code uses the compiler options "--allowJs" in combination with "--declaration" (TypeScript 3.7) to generate typings from JavaScript code.
2. Benefits
• JavaScript library authors can bootstrap definition files
• Automatically generated definitions can be compared with manually
typed definitions (using third-party tools like TSEvolve)
Limitations
• --module flag must be „amd“ or „system“ (doesn‘t work with „esnext“)
to use --out
• Exports get wrapped in modules
• Exported classnames can interfere with module name
2019/12/17
3. Demo
tsc src/Point.js --allowJs --declaration --out dist/Point.js --module system
• --allowJs combined with --declaration
(available with TypeScript 3.7)
2019/12/17