angulardart-community / angular

Fast and productive web framework provided by Dart.
https://pub.dev/packages/ngdart
MIT License
111 stars 14 forks source link

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

Open insinfo opened 1 year ago

insinfo commented 1 year ago

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

GZGavinZhao commented 1 year ago

Is this a warning only, or does it also break stuff?

insinfo commented 1 year ago

warning only