Improve how AoT compiler casts to boolean
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
Current behavior
During ngc
compilation, I get several errors of the type:
Type 'IDrillActive' is not assignable to type 'boolean'.
As the compiler parses auto-generated code:
const currVal_0:boolean = (!this.context.store.appState.loading && this.context.drill);
These errors from .ngfactory.ts
files clutter the IDE and make it tougher to spot errors in my own code.
Expected behavior
I think it would be better to properly cast expressions to booleans. For instance the line above could be re-factored to:
const currVal_0:boolean = !!(!this.context.store.appState.loading && this.context.drill);
What is the motivation / use case for changing the behavior?
To reduce compiler errors generated by .ngfactory.ts
files
Please tell us about your environment:
- Angular version: 2.0.0-rc.6
- Browser: [all]
- Language: [TypeScript 2.0.2]
- Node (for AoT issues):
node --version
= 4.5.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Avoiding AoT compilation issues when using ngIf with non ...
Avoiding AoT compilation issues when using ngIf with non boolean values ... Cast truthy values into booleans using the !! operator
Read more >Ahead-of-time Compilation of FastR Functions Using ... - Oracle Labs
Abstract. The FastR project delivers high peak-performance through the use of JIT-compilation, but cannot currently provide this performance.
Read more >Ahead of Time Compilation - AoT in Angular (Performance ...
Abstract: This Angular tutorial explains how Angular uses Ahead of Time (AoT) compilation on the browser and then demonstrates how it improves ......
Read more >The Ahead-of-Time (AOT) compiler - Angular
The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the ...
Read more >Ahead-of-time (AOT) compilation - Angular
The AOT compiler detects and reports template binding errors during the build step before users can see them. Better security, AOT compiles HTML...
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
@vvakame the problem is with our code, not Angular.
This resolves to a string because the 2nd operand is a string. If you don’t want to see these errors, you need to adjust your conditional statements to return booleans, not just truthey values. For instance you could do:
Typescript resolves this to a boolean (the type of the last operand) so you won’t see the error.
Alternatively, you could force your non-booleans into booleans with the
!!
prefix:This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.