Skip to content

Operand of null-aware operation '?.' has type 'String' which excludes null, when passing a string to a native directive #58

@insinfo

Description

@insinfo

Which ng* package(s) are the source of the bug?

ngcompiler, ngdart

Which operating system(s) does this bug appear on?

Windows

Which browser(s) does this bug appear on?

Chrome 113.0.5672.93

Is this a regression?

No

Description

Operand of null-aware operation '?.' has type 'String' which excludes null, when passing a string to a native directive

Please provide the steps to reproduce the bug

create a new project with AngularDart 7, create a component and place some html using some default directive like class, style passing some value as shown below.

<span class="d-none d-lg-inline-block mx-lg-2">
   <div>
    <div #divName>
             {{ $pipe.titleCase(authService.authPayload.nomCgm) }}
     </div>
     <div class="fs-xs" [style.width]="divName.offsetWidth.toString() + 'px'" style="text-overflow: ellipsis;background: none;border: none;overflow: hidden; white-space: nowrap;">
              {{ $pipe.titleCase(authService.authPayload.nomSetor) }}
          </div>
    </div>
</span>

Please provide the exception or error you saw

Warning: Operand of null-aware operation '?.' has type 'String' which excludes null.


webdev serve web:8005 --auto refresh
[WARNING] Throwing away cached asset graph because the build phases have changed. This most commonly would happen as a result of adding a new dependency or updating your dependencies.
[WARNING] Throwing away cached asset graph because the language version of some package(s) changed. This would most commonly happen when updating dependencies or changing your min sdk constraint.
[INFO] Cleaning up outputs from previous builds. completed, took 1.9s
[INFO] Building new asset graph completed, took 2.8s
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Serving `web` on http://127.0.0.1:8005
[INFO] build_web_compilers:ddc on lib/new_sali_frontend.ddc.module:
packages/new_sali_frontend/src/modules/home/components/main_nav/main_nav.template.dart:157:46: Warning: Operand of null-aware operation '?.' has type 'String' which excludes null.
      this._el_20.style.setProperty('width', currVal_1?.toString()) /* REF:package:new_sali_frontend/src/modules/home/components/main_nav/main_nav.html:1561:1614 */;
                                             ^
[INFO] Running build completed, took 1m 7s
[INFO] Caching finalized dependency graph completed, took 592ms
[INFO] Succeeded after 1m 7s with 5265 outputs (13680 actions)
[INFO] ------------------------------------------------------------------------------------------------------------------------------------- 
[INFO] Updating asset graph completed, took 5ms
[INFO] build_web_compilers:ddc on lib/new_sali_frontend.ddc.module:
packages/new_sali_frontend/src/modules/home/components/main_nav/main_nav.template.dart:156:46: Warning: Operand of null-aware operation '?.' has type 'String' which excludes null.
      this._el_20.style.setProperty('width', currVal_1?.toString()) /* REF:package:new_sali_frontend/src/modules/home/components/main_nav/main_nav.html:1545:1598 */;
                                             ^
[INFO] Running build completed, took 9.5s
[INFO] Caching finalized dependency graph completed, took 512ms
[INFO] Succeeded after 10.0s with 52 outputs (49 actions)

Please provide the dependency environment you discovered this bug in (run dart pub deps -s compact)

environment:   
  sdk: '>=2.18.0 <3.0.0'

dependencies:   
  ngdart: ^7.1.1 
  ngforms: ^4.1.1
  ngrouter: ^3.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions