Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Template compiles with strict but not with fullΒ #35650

@jgbpercy

Description

@jgbpercy

🐞 bug report

Affected Package

The issue is caused by package @angular/compiler (I guess)

Is this a regression?

Yes, kiiiiinda

With enableIvy false (v9 and I'm almost certain v8 as well), changing the final non-null assert (!) in the template into a null propagation (?) makes the error go away.

Description

The code in the reproduction below compiles with "strictTemplate": true in tsconfig, but not with "fullTemplateTypeCheck": true only.

As far as I understand, anything that compiles with strict should compile with full? As an aside, I think it would be good if that was made clear one way or another in this section of the docs (happy to raise a separate issue).

Furthermore, the error in full mode doesn't make any sense, as far as I understand.

As noted above, there is a similar issue with Ivy disabled, but for reasons I don't understand it goes away when using null propagation rather than non-null assertion.

πŸ”¬ Minimal Reproduction

https://github.com/jgbpercy/AngularCompilesOnlyStrict
(currently the repo should be in a non-compiling state - add "strictTemplate": true to tsconfig angularCompilerOptions and it should compile)

πŸ”₯ Exception or Error


ERROR in src/app/app.component.html:2:12 - error TS2339: Property 'doDar' does not exist on type 'never'.

2   
{{ (thinger!.innerObs | async)!.doDar }}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/app/app.component.ts:14:16 14 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.3
Node: 10.15.0
OS: win32 x64

Angular: 9.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.3
@angular-devkit/build-angular     0.900.3
@angular-devkit/build-optimizer   0.900.3
@angular-devkit/build-webpack     0.900.3
@angular-devkit/core              9.0.3
@angular-devkit/schematics        9.0.3
@angular/cli                      9.0.3
@ngtools/webpack                  9.0.3
@schematics/angular               9.0.3
@schematics/update                0.900.3
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

Anything else relevant?
The language service thinks the code is fine and picks up the type ok!

So I'm guessing in full the first | async is polluting the type it outputs with a union to null, and then the second | async is chewing up horribly on that somehow. Whereas in strict it has enough information to know that null isn't part of the relevant type at the right time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions