Taking variables into account when checking for possible null values TS2532 #42446
Closed
5 tasks done
Labels
Duplicate
An existing issue was already created
Suggestion
I excuse in advance for opening this if this is too expensive too implement.
I think it might be useful to some though.
π Search Terms
all included below
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
If an if statement only contains a single local constant variable, the compiler should inline the variable into the if statement (if the contents can be locally inferred) when checking for undefined variables.
If that sounds complicated to you, I suggest to check out the example below.
π Motivating Example
This does not compile:
but this does:
although they are basically the same code.
The information is there to deduce that start can never be undefined, so it could be used in theory.
π» Use Cases
This can prevent uneccessary null checks or executing code twice that only needs to be executed once.
Can also help readability. The current workaround is to duplicate the logic
The text was updated successfully, but these errors were encountered: