umi-examples
umi-examples copied to clipboard
空值检查
我希望umi可以对null值做严格的测试(不要给对象赋值null!编译的时候就报错)。demo如下:
- 测试代码:
it("test null check", () => {
let name:string = null
expect(name).toBe(null)
})
- tsconfig.json "strictNullChecks": true
- test命令
umi test
没明白问题,这不是自己配 tsconfig.json 能解决的吗?
没明白问题,这不是自己配 tsconfig.json 能解决的吗?
我贴的是测试代码,没有达到目的。你怎么配置的?
"strict": true,
"strict": true,
为了让结果更明显,我改了测试代码,如下:
function allowNull(name?:string):boolean{
return name == null
}
function notAllowNull(name:string):boolean{
return name == null
}
it("check null value", () => {
let name:string = null
expect(allowNull(name)).toBeTruthy()
expect(notAllowNull(name)).toBeTruthy()
})
