GithubHelp home page GithubHelp logo

Comments (2)

alxhub avatar alxhub commented on June 21, 2024

Without an actually runnable reproduction it's impossible to verify, but it looks to me like the type-checking error is correct per your types. user.contracts.length > 0 is not a safe expression to execute since user.contracts is potentially undefined (declared optional: contracts?: Array<AnyContractDTO>), and nothing guards its access.

from angular.

dreamstar-enterprises avatar dreamstar-enterprises commented on June 21, 2024

I tried again. - it definitely doesn't work

This doesn't work

        @if(user().contracts && user().contracts?.length > 0) {
          <p class="contract-info">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="red" class="contract-svg" width="24" height="24" focusable="false">
              <path d="M13 13h5v1h-5zm5-5H6v3h12zm-5 8h5v-1h-5zm9-12v13a3 3 0 01-3 3H5a3 3 0 01-3-3V4zm-2 2H4v11a1 1 0 001 1h14a1 1 0 001-1zm-9 7H6v3h5z"></path>
            </svg>
            {{ user().contracts?.length }}  @if(user().contracts?.length == 1) { contract } @else { contracts }
          </p>
        }

Neither does this:

        @if(user().contracts && user().contracts.length > 0) {
          <p class="contract-info">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="red" class="contract-svg" width="24" height="24" focusable="false">
              <path d="M13 13h5v1h-5zm5-5H6v3h12zm-5 8h5v-1h-5zm9-12v13a3 3 0 01-3 3H5a3 3 0 01-3-3V4zm-2 2H4v11a1 1 0 001 1h14a1 1 0 001-1zm-9 7H6v3h5z"></path>
            </svg>
            {{ user().contracts?.length }}  @if(user().contracts?.length == 1) { contract } @else { contracts }
          </p>
        }

But this does:

@if(user().contracts; as contracts) {
        @if(contracts && contracts.length > 0) {
          <p class="contract-info">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="red" class="contract-svg" width="24" height="24" focusable="false">
              <path d="M13 13h5v1h-5zm5-5H6v3h12zm-5 8h5v-1h-5zm9-12v13a3 3 0 01-3 3H5a3 3 0 01-3-3V4zm-2 2H4v11a1 1 0 001 1h14a1 1 0 001-1zm-9 7H6v3h5z"></path>
            </svg>
            {{ contracts?.length }}  @if(contracts?.length == 1) { contract } @else { contracts }
          </p>
        }
      }

If I do:

contracts && contracts?.length > 0

It fails, bizarrely. (same object undefined message)

Screenshot 2024-06-13 at 07 44 50

I think this is a typescript issue, as it's not doing a smart casting of the second condition against the '>' check.

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.