-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
背景
当前使用 TypeScript 开发 Egg ,会面临的影响开发者体验问题:
- Egg 最精髓的 Loader 自动加载机制,导致 TS 无法静态分析出部分依赖,譬如
app/service/news.ts会自动挂载为ctx.service.news。 - Egg 的 Config 自动合并机制下,如何在
config.{env}.js里面修改插件提供的配置时,能校验并智能提示? - 开发期需要独立开一个
tsc -w独立进程来构建代码,带来临时文件位置纠结以及npm scripts复杂化。 - 单元测试,覆盖率测试,线上错误堆栈如何指向 TS 源文件,而不是编译后的 js 文件。
思路
- 约束
- Egg 目前没有计划使用 TS 重写。
- Egg 以及它对应的插件,提供对应的 index.d.ts 文件方便开发者使用。
- 通过 TS 的 Declaration Merging 编写 d.ts 来辅助定位。
- 使用 TS 2.8 提供的 Conditional Types 黑魔法。
- 通过工具链方面的支持,在开发期无需编译 TS
- egg loader 支持开发期加载 ts 文件
- egg-bin 等工具支持 sourcemap 和 ts-node
- 同样需引入工具链映射 sourcemap
事项
- egg-core loader : feat: loader support custom extension core#156
- egg-cluster : feat: add typescript support cluster#61
- egg-bin : feat: support typescript bin#89
- common-bin : fix: execArgv convert rule node-modules/common-bin#20
-
--require: fix: --require node-modules/common-bin#21 - nyc cov 覆盖率: feat: cov support typescript bin#91
- 支持读取
egg.typescript: feat: support egg.typescript bin#92 ts-node 的 tsc 版本
- egg-mock
- egg-view-nunjucks: feat: support ts filter egg-view-nunjucks#27
- egg-scripts
- support sourcemap error stack feat: provides source map support for stack traces scripts#19
- 自动生成
d.ts- egg-ts-helper : https://github.com/whxaxes/egg-ts-helper - docs
- example
- d.ts chore: improve d.ts with ts support #2306
- boilerplate https://github.com/eggjs/egg-boilerplate-ts
后续
以下内容不属于本期内容,仅做备忘,后续跟进
- autod
- pkgfiles
- egg-di : https://github.com/shepherdwind/egg-di
- tegg
shepherdwind, desenmeng, leoyoung07, vagusX, shyser and 21 more