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

Errors with noUnusedLocals #65

Closed
hiro-hori opened this issue Aug 9, 2017 · 14 comments · Fixed by #103
Closed

Errors with noUnusedLocals #65

hiro-hori opened this issue Aug 9, 2017 · 14 comments · Fixed by #103

Comments

@hiro-hori
Copy link

hiro-hori commented Aug 9, 2017

In my project, we use stricter TypeScript option i.e.noUnusedLocals
I saw compilation error from ngx-clipboard.

src/clipboard.directive.ts(3,5): error TS6133: 'ElementRef' is declared but never used.
src/clipboard.service.ts(1,60): error TS6133: 'InjectionToken' is declared but never used.

It seems easy to fix, so I tried to fix it.
But it was difficult.

After I deleted importing InjectToken from src/clipboard.service.ts, I met a new error.

src/clipboard.service.ts(105,14): error TS4023: Exported variable 'CLIPBOARD_SERVICE_PROVIDER' has or is using name 'InjectionToken' from external module "/work/ngx-clipboard/node_modules/@angular/core/src/di/injection_token" but cannot be named.

That error seems microsoft/TypeScript#5711

I really want to solve this problem, does anyone have good ideas?

@maxisam
Copy link
Owner

maxisam commented Aug 9, 2017

yeah, I have no idea how to fix the 2nd one. However, I fixed the first one. I think you can use "skipLibCheck": true to suppress this.

@hiro-hori
Copy link
Author

hiro-hori commented Aug 9, 2017

I think you can use "skipLibCheck": true to suppress this.

Thank you for advice!

But... I think what you are saying is wrong (sorry).
First, We've already use skipLibCheck option.

Second If setting skipLibCheck=true, the compiler skips type checking of *.d.ts files.
But ngx-clipboard does not have d.ts file, doesn't it?

--skipLibCheck Skip type checking of all declaration files (*.d.ts).
https://www.typescriptlang.org/docs/handbook/compiler-options.html


For this argument's information, I paste our tsconfig.

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "../dist/out-tsc",
    "skipLibCheck": true,
    "sourceMap": true,
    "strictNullChecks": true,
    "target": "es5"
  }
}

@maxisam
Copy link
Owner

maxisam commented Aug 9, 2017

It has d.ts. Check your node_module folder. I think you might have 2 tsConfigs one for build one for IDE. I believe skipLibCheck is the answer. Maybe you can check with Stackoverflower on this.

@linsolas
Copy link

linsolas commented Sep 4, 2017

Hello all,

I wanted to use the ngx-clipboard library, but faced also this TSLint error. After trying - without luck - to exclude the library from TSLint configuration, I've tried to simply removed the two unused declarations. Unlike @hiro-hori, I didn't encounter any issue afterwards, and the library works great.

Some information that may help:

  • @angular/core v4.3.5
  • @angular/cli v1.3.1
  • @typescript v2.4.2
  • @tslint v5.6.0

@linsolas
Copy link

linsolas commented Sep 4, 2017

For information, I changed my import from:

import { ClipboardModule } from 'ngx-clipboard';

to:

import { ClipboardModule } from 'ngx-clipboard/dist';

and the error is now gone (as I rely on JS and not on TS files now)

@maxisam
Copy link
Owner

maxisam commented Sep 5, 2017

@linsolas what version of ngx-clipboard do you use? I think this might be related to #69

@linsolas
Copy link

linsolas commented Sep 5, 2017

@maxisam I've used the latest one, which means 8.0.4.

@sandrocsimas
Copy link

sandrocsimas commented Oct 9, 2017

The same here!
This is my tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "strictNullChecks": false,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "removeComments": true,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "lib": ["es6", "dom"]
  },
  "typeRoots": [
    "../node_modules/@types",
    "./types"
  ]
}

I'm using webpack and the output is:

ERROR in /home/sandro/chatz-website/node_modules/ngx-clipboard/src/clipboard.service.ts
(1,60): error TS6133: 'InjectionToken' is declared but never used.

ERROR in ./node_modules/ngx-window-token/src/index.ts
Module parse failed: /home/sandro/chatz-website/node_modules/ngx-window-token/src/index.ts Unexpected token (6:25)
You may need an appropriate loader to handle this file type.
| export const WINDOW = new InjectionToken<Window>('WindowToken');
| 
| export function _window(): Window {
|     return window;
| }
 @ ./node_modules/ngx-window-token/index.ts 1:0-56
 @ ./node_modules/ngx-clipboard/dist/src/index.js
 @ ./node_modules/ngx-clipboard/dist/index.js
 @ ./client/src/app/app.module.ts
 @ ./client/src/main.ts

@sandrocsimas
Copy link

@maxisam, with the latest version (8.1.1) I got only one error:

ERROR in /home/sandro/chatz-website/node_modules/ngx-clipboard/src/clipboard.service.ts
(1,60): error TS6133: 'InjectionToken' is declared but never used.
import { Inject, Injectable, Optional, Renderer, SkipSelf, InjectionToken } from '@angular/core';

This can be easily solved by removing InjectionToken since its not used in this file.

@maxisam
Copy link
Owner

maxisam commented Oct 17, 2017

@sandro-csimas as I mentioned before, I actually don't know how to fix it. I think it might be typescript's issue. I can't remove that import and build successfully.

@sandrocsimas
Copy link

@maxisam , InjectionToken is not used in this file.

ngx-clipboard/src/clipboard.service.ts

@maxisam
Copy link
Owner

maxisam commented Oct 17, 2017

I know. You can try to build it yourself.

@maxisam maxisam closed this as completed Oct 17, 2017
@maxisam maxisam reopened this Oct 17, 2017
@sandrocsimas
Copy link

@maxisam , OK, I will try.

@maxisam
Copy link
Owner

maxisam commented Oct 17, 2017

https://travis-ci.org/maxisam/ngx-clipboard/builds/259478307 This was the build record for the commit trying to remove that import. But maybe typescript fix the bug now if so, feel free to submit a PR.

SafeEval added a commit to SafeEval/ngx-clipboard that referenced this issue Jan 12, 2018
SafeEval added a commit to SafeEval/ngx-clipboard that referenced this issue Jan 12, 2018
Build passes with noUnusedLocals compiler option.
Fix involved explicit casting with InjectionToken<Document>.

fix maxisam#65
SafeEval added a commit to SafeEval/ngx-clipboard that referenced this issue Jan 12, 2018
Build passes with noUnusedLocals compiler option.
Fix involved explicit casting with InjectionToken<Document>.

fix maxisam#65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants