Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

空值检查 #44

Open
yuri-li opened this issue Jun 2, 2019 · 4 comments
Open

空值检查 #44

yuri-li opened this issue Jun 2, 2019 · 4 comments

Comments

@yuri-li
Copy link

yuri-li commented Jun 2, 2019

我希望umi可以对null值做严格的测试(不要给对象赋值null!编译的时候就报错)。demo如下:

  1. 测试代码:
it("test null check", () => {
    let name:string = null
    expect(name).toBe(null)
})
  1. tsconfig.json
    "strictNullChecks": true
  2. test命令
    umi test
@sorrycc
Copy link
Member

sorrycc commented Jun 3, 2019

没明白问题,这不是自己配 tsconfig.json 能解决的吗?

@yuri-li
Copy link
Author

yuri-li commented Jun 5, 2019

没明白问题,这不是自己配 tsconfig.json 能解决的吗?

我贴的是测试代码,没有达到目的。你怎么配置的?

@xiaohuoni
Copy link
Member

"strict": true,

@yuri-li
Copy link
Author

yuri-li commented Jun 5, 2019

"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()
})

null-check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants