Here's the companion code to the talk Vue.js and TypeScript: Working Together like Peanut Butter and Jelly
Each step in this codebase represents a step of exploration / improvement for this Vue 2 app.
Noteable discoveries when including JavaScript code into a TypeScript project like this:
- Step 7: exporting interfaces to shim in understanding
- Step 9: creating type declaration file (
.d.ts
) - Step 11: generating type declaration file
When including JavaScript in TypeScript, here's a prioritized list of strategies:
- Use libraries built in TypeScript
- Install
@types/your-lib
to get their type declaration file - Hand-craft a declaration file (
.d.ts
) - Generate declaration file to get started, then tune to fit
mv file.js file.ts; tsc --declaration file.ts
- Use any (this is often a bad idea)
const ok = bad as any;
- Ignore it (this is often a bad idea)
// @ts-ignore