question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve how AoT compiler casts to boolean

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
RoxKillycommented, Sep 11, 2016

@vvakame the problem is with our code, not Angular.

!loggedIn && loginURL

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:

loginURL && !loggedIn

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:

!loggedIn && !!loginURL
0reactions
angular-automatic-lock-bot[bot]commented, Sep 11, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found