作者:刘辉
最近笔者把一个中等规模的 Koa2 项目迁移到 TypeScript,和大家分享一下 TypeScript 实践中的经验和技巧。
原项目基于 Koa2,MySQL,sequelize,request,接口加页面总计 100 左右。迁移后项目基于 Midway,MySQL,sequelize-typescript,axios。
本项目使用 TypeScript3.7,TypeScript 配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| "compilerOptions": { "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "incremental": true, "inlineSourceMap": true, "module": "commonjs", "newLine": "lf", "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "outDir": "dist", "pretty": true, "skipLibCheck": true, "strict": true, "strictPropertyInitialization": false, "stripInternal": true, "target": "ES2017" }
|
本文分为两部分,第一部分是处理 any 的实践,第二部分是构建类型系统的实践。