Umi: [Typescript]如何在提交时的 hook 中强制检查 TS 编译是否存在错误呢

Created on 8 Mar 2019  ·  3Comments  ·  Source: umijs/umi

用 UMI 创建项目后,开发模式下可以通过设置 FORK_TS_CHECKER 变量值来开启 TS 校验,我想在提交 commit 时像 ESlint 那样对所有文件做 TS 校验,通过后才允许提交,这个要怎么实现呢?

Most helpful comment

找到一个方案,在 pre-commit 里再添加一个运行 TS 编译检查的命令,但感觉不够优雅 🤨

~~~json
{
"scripts": {
"ts-compile-check": "tsc -p tsconfig.json"
},
"husky": {
"hooks": {
"pre-commit": "npm run ts-compile-check && npm run lint-staged"
}
}
}

~~~

All 3 comments

找到一个方案,在 pre-commit 里再添加一个运行 TS 编译检查的命令,但感觉不够优雅 🤨

~~~json
{
"scripts": {
"ts-compile-check": "tsc -p tsconfig.json"
},
"husky": {
"hooks": {
"pre-commit": "npm run ts-compile-check && npm run lint-staged"
}
}
}

~~~

👍

tsconfig.json 中加入

"noEmit": true,

就够优雅了吧

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Artoria-0x04 picture Artoria-0x04  ·  3Comments

kitebear picture kitebear  ·  3Comments

miaojinxing picture miaojinxing  ·  3Comments

sorrycc picture sorrycc  ·  4Comments

ddzy picture ddzy  ·  3Comments