Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ivy marks unassigned but used child interfaces as unused with compiler warning. #15626

Closed
jkyoutsey opened this issue Sep 18, 2019 · 12 comments · Fixed by #16148
Closed

Ivy marks unassigned but used child interfaces as unused with compiler warning. #15626

jkyoutsey opened this issue Sep 18, 2019 · 12 comments · Fixed by #16148

Comments

@jkyoutsey
Copy link

🐞 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 <any> 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
@ngbot ngbot bot added this to the needsTriage milestone Sep 19, 2019
@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix labels Sep 19, 2019
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Sep 19, 2019
@mhadji
Copy link

mhadji commented Sep 19, 2019

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.

@jkyoutsey
Copy link
Author

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.

@Ghostbird
Copy link

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> { }

@mhadji
Copy link

mhadji commented Sep 20, 2019

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

@jkyoutsey
Copy link
Author

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

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Sep 25, 2019

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.

@Splaktar
Copy link
Member

Splaktar commented Oct 1, 2019

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.

@sharikovvladislav
Copy link

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.

@Splaktar
Copy link
Member

Splaktar commented Oct 10, 2019

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

@alan-agius4 alan-agius4 added freq2: medium and removed freq1: low Only reported by a handful of users who observe it rarely labels Nov 3, 2019
@alan-agius4 alan-agius4 modified the milestones: Backlog, 9.0.x Nov 3, 2019
@filipesilva filipesilva self-assigned this Nov 7, 2019
@vikerman vikerman modified the milestones: v9-candidates, v9-blockers Nov 7, 2019
@shral
Copy link

shral commented Nov 8, 2019

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

@filipesilva
Copy link
Contributor

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

filipesilva added a commit to filipesilva/angular-cli that referenced this issue Nov 11, 2019
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Nov 11, 2019
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 13, 2019
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.