采用以下Typescript箭头功能:
/**
* Returns a probably unique component name.
*
* @param baseName a suggested name to make unique.
* @returns a probably unique name.
*/
export const getUniqueComponentName = (
baseName
): string => {
return baseName + Math.round(Math.random() * 10000000)
}
Run Code Online (Sandbox Code Playgroud)
当Typescript配置tsconfig.json为这样时:
"noImplicitAny": true,
Run Code Online (Sandbox Code Playgroud)
这正确导致编译错误:
[ts]参数'baseName'隐式具有'any'类型.
Visual Studio Code也非常智能,可以在开发过程中告知您这个问题.
我的目标是创建一个precommit git hook,以防止此类错误在版本控制中结束.我试着这样做tslint,husky并lint-staged使用这个npm script:
"lint": "tslint --project tsconfig.json --config tslint.json"
Run Code Online (Sandbox Code Playgroud)
但是,这不会导致tslint显示编译错误.它被默默地忽略了.
然后我尝试在tslint.json中添加一条规则:
"typedef": [
true,
"arrow-parameter"
]
Run Code Online (Sandbox Code Playgroud)
虽然这确实让tslint抱怨,但它也开始抱怨匿名箭头函数,tsc …
是否可以仅针对构建排除所有测试文件,但将它们与 nodemon 一起使用以在本地运行测试?当我在tsconfig.json文件中排除测试文件时,我收到一个打字稿错误,在我的情况下,它找不到像 jest 这样的测试库的类型。
Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.ts(2582)
{
"compilerOptions": {},
"exclude": [
"**/*.test.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我想知道,因为我猜临时转译被放入另一个文件夹而不是构建文件夹。