Angular-cli: Ivy marks unassigned but used child interfaces as unused with compiler warning.

Created on 18 Sep 2019  路  12Comments  路  Source: angular/angular-cli

馃悶 Bug report

Command (mark with an x)

- [ x] new
- [ x] build
- [ x] serve

Is this a regression?

Yes

Description

Ivy incorrectly identifies interfaces as unused that compose parts of an object returned from an API endpoint. i.e. Type A that contains Type B, if Type B is never assigned to and is in it's own TS file, Ivy generates warnings that Type B is not an entry point.

Workarounds:

  • Move the interface into the same file as the parent object interface.
  • Inline the child interface into the parent interface rather than defining a new type.
  • Define A.B as rather than strongly typing it.

馃敩 Minimal Reproduction

https://github.com/fivedice/ivy-warnings
See the ReadMe.md for specific example in the repo.

馃敟 Exception or Error


WARNING in /Users/jyoutsey/src/fivedice/ivy-warnings/src/app/currency.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

WARNING in /Users/jyoutsey/src/fivedice/ivy-warnings/src/environments/environment.prod.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

馃實 Your Environment


Angular CLI: 9.0.0-next.4
Node: 10.16.0
OS: darwin x64
Angular: 9.0.0-next.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-next.4
@angular-devkit/build-angular     0.900.0-next.4
@angular-devkit/build-optimizer   0.900.0-next.4
@angular-devkit/build-webpack     0.900.0-next.4
@angular-devkit/core              9.0.0-next.4
@angular-devkit/schematics        9.0.0-next.4
@angular/cli                      9.0.0-next.4
@ngtools/webpack                  9.0.0-next.4
@schematics/angular               9.0.0-next.4
@schematics/update                0.900.0-next.4
rxjs                              7.0.0-alpha.0
typescript                        3.7.0-dev.20190918
webpack                           4.39.3
ngtoolwebpack medium broken bufix

Most helpful comment

I think that this should be higher than freq1: low since most real world apps of significant size are likely to run into this.

All 12 comments

in my case, it complains about environment files
WARNING in ..ClientApp/src/environments/environment.demo.ts is part of the TypeScript compilation but it's unused.

WARNING in. .. ClientApp/src/environments/environment.dev.ts is part of the TypeScript compilation but it's unused.

WARNING in ... ClientApp/src/environments/environment.prod.ts is part of the TypeScript compilation but it's unused.

WARNING in D ...ClientApp/src/environments/environment.qa.ts is part of the TypeScript compilation but it's unused.

I'm currently trying with v9 and it appears to have wiped out my excludes, which excluded the environment ts files that I didn't want and my wallaby setup.

I have this same issue exactly as described above.
In addition I have the same message for this file:

interface Exception {
    Identifier?: number;
    Message: string;
    CustomData?: any;
}

Which has 13 references in the code e.g:

const x = result.error as Exception;
var y: Exception;
func(): Observable<Exception> { }

I did
"exclude": [
"test.ts",
"*/.spec.ts",
"../../ClientApp/src/environments/ *.ts"
in tsconfig.app.json , and my problem had solved.

With Ivy v9 I don't need the excludes for environment. But even excluding the offending interfaces will not work.

Hi all,

For most cases you should update your tsconfig.app.json config to the below

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

Note: that if you use ng update the tsconfig file will be migrated automatically.

Thank you for opening this and noting the workarounds! I am going to have to apply some of these to the update of material.angular.io.

As @alan-agius4 said, updating your tsconfig.app.json will fix the environment.ts types of issues.

However, it won't solve the other issues where unassigned child interfaces are incorrectly marked as unused.

We have a lot of warnings like mentioned in the issue.

WARNING in /Users/vladislav.sharikov/git/project/src/some/path/to/any-util.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

In tsconfig I have the following lines:

  // ...
  "include": [
    "src/**/*.ts",
    "declarations.d.ts"
  ],
  // ...

Notice, that I have a hybrid application with JavaScript (AngularJS) code. Thats why, sometimes, it is possible that TS file is imported to JS file. Probably, some of warnings can be caused by this fact. Am I right?

@alan-agius4 Following your comment above, I changed it to this one:

// ...
"files": [
  "ccm/index.ts"
],
"include": [
  "ccm/**/*.ts",
  "**/*.d.ts"
],
// ...

Now I am getting the error below:

ERROR in ./src/path/to/any.enum.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Users/vladislav.sharikov/git/project/src/path/to/any.enum.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

It is just one of the errors. I have tons of such errors.

The main question: 小an you explain in more detail why I was getting warning (before the config change) and why I am getting the error (after I changed the config) now? Please.

I think that this should be higher than freq1: low since most real world apps of significant size are likely to run into this.

After activating ivy in my project (Angular 8.2.12) I had those two warnings by calling ng build --aot --prod:

WARNING in [...]src/main.ngsummary.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

WARNING in [...]src/polyfills.ngsummary.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

I fixed by removing the parameter "allowEmptyCodegenFiles": true from angularCompilerOptions in tsconfig.app.json

@shral those should be ignored automatically, but it looks like they weren't (which is a bug).

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._

Was this page helpful?
0 / 5 - 0 ratings