Truthy value check, but red highlighting for undefined
See original GitHub issueDescribe the bug
If you check a variable in HTML has a truthy value (not null, not undefined, …) and call then a method on it, I get an error with unknown method because VSCode believes object can be undefined.
Example:
{{ foo && foo.bar() }}
In my example, I consider foo : Type | undefined;
To Reproduce
Just implement a similar simple foo
attribute in an Angular component and try to call a method in the template checking truthy first.
Expected behavior
No red highlighting as value is checked using foo &&
Screenshots
In this case, startModelInstance
is defined as public startModelInstance?: ModelInstance;
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Using a truthy/falsy check in Typescript vs explicit check ...
I understand that null and undefined are different. I understand that the !myBar.foo is a broader check in normal Javascript. But in TS-land, ......
Read more >VS Code API | Visual Studio Code Extension API
For some languages one color can have multiple presentations, e.g. css can represent the color red with the constant Red , the hex-value...
Read more >CodeMirror 5 User Manual
The value "null" indicates no highlighting should be applied. Alternatively, it may be an object containing configuration options for the mode, ...
Read more >Manage Symbols in the Stateflow Editor - MATLAB & Simulink
Resolve Symbols Through the Symbols Pane. As you edit your chart, Stateflow detects undefined symbols and marks them in the Symbols pane with...
Read more >nunjucks templating docs
If a value is undefined or null , nothing is displayed. The same behavior occurs when referencing undefined or null objects. The following...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
you can use this example:
Use strict mode in tsconfig: