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鈥檒l 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

Open
jkyoutsey opened this issue Sep 18, 2019 · 9 comments

Comments

@jkyoutsey
Copy link

commented Sep 18, 2019

馃悶 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
@mhadji

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Author

commented Sep 19, 2019

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

This comment has been minimized.

Copy link

commented Sep 20, 2019

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Author

commented Sep 20, 2019

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

@alan-agius4

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Oct 7, 2019

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

This comment has been minimized.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can鈥檛 perform that action at this time.