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

Need a flag to check if checking an expression for null or undefined has not that types #14839

Closed
cevek opened this issue Mar 24, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@cevek
Copy link

cevek commented Mar 24, 2017

Often we have to check variables for empty values.
If variables has undefined or null types we check for that types.
But if we want to refactor our code, and replace nullable variables to always with value, we init its with empty values like false, 0, -1, ""
But checks that variables for null or undefined in other parts of program are still there, and make a lot of bugs

let a: string | undefined;
if (a !== undefined) {
   foo(a);
}

// and if we refactor

let a = '';
// In this check we potentially has a bug, cause undefined is not possible here, 
if (a !== undefined) {
   foo(a);
}
@cevek cevek changed the title Need a flag to suppress checks for null or undefined Need a flag to throw an error if the checks expression for null or undefined has not that types Mar 24, 2017
@cevek cevek changed the title Need a flag to throw an error if the checks expression for null or undefined has not that types Need a flag to check if checking an expression for null or undefined has not that types Mar 24, 2017
@ghost
Copy link

ghost commented Mar 24, 2017

https://palantir.github.io/tslint/rules/strict-type-predicates/ attempts this. It could use #13502 to work even better, but should be capable of handling undefined checks already.

@cevek
Copy link
Author

cevek commented Mar 30, 2017

Another issue linked with this one

// no error
if (typeof v === null) {} 
if (typeof v === undefined) {} 

typeof v is always string, and check with raw null or undefined is incorrect

@RyanCavanaugh
Copy link
Member

Covered by #14764?

@cevek
Copy link
Author

cevek commented Mar 30, 2017

@RyanCavanaugh yeah, it's the same what I want

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 30, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants