You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While checking whether a variable is undefined or null, checker should go through all the code including the function runned before the variable is used.
Use Cases
I have a function that required a non-undefined argument. I do the required field check in a separate function and if the required variable is undefined or null, it should throw an error and the variable is not really used.
However, the checker now is still showing me the error that this variable might be undefined.
Examples
class example {
private property: string
public assignVariable (variable: string | undefined) {
this.checkRequiredVariable(variable)
this.property = variable // This is throwing the "Type 'undefined' is not assignable to type 'string'." error.
}
private checkRequiredVariable (variable: string | undefined) {
if (variable == undefined)
throw new Error('Variable is undefined or null')
}
}
PS: This code is just for the example, I know that this will throw a "No initialization" error as well.
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript / JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. new expression-level syntax)
The text was updated successfully, but these errors were encountered:
@DanielRosenwasser He does mention this kind of thing but mine is not that complicated. If you think it's a duplication I'll accept that. Sorry for the duplicated issue.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Search Terms
variable, check, undefined
Suggestion
While checking whether a variable is undefined or null, checker should go through all the code including the function runned before the variable is used.
Use Cases
I have a function that required a non-undefined argument. I do the required field check in a separate function and if the required variable is undefined or null, it should throw an error and the variable is not really used.
However, the checker now is still showing me the error that this variable might be undefined.
Examples
PS: This code is just for the example, I know that this will throw a "No initialization" error as well.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: