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

noImplicitAny checks node_modules despite skipLibCheck #15363

Closed
sciolizer opened this issue Apr 24, 2017 · 6 comments
Closed

noImplicitAny checks node_modules despite skipLibCheck #15363

sciolizer opened this issue Apr 24, 2017 · 6 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@sciolizer
Copy link

TypeScript Version: 2.2.2

Code

package.json:

{
  "devDependencies": {
    "@types/es6-promise": "0.0.32",
    "@types/node": "^7.0.12",
    "typescript": "^2.2.2"
  },
  "dependencies": {
    "k8s": "^0.4.13"
  }
}

tsconfig.json:

{
    "compilerOptions": {
        "noImplicitAny": true,
        "strictNullChecks": true,
        "outDir": "dist",
        "skipDefaultLibCheck": true,
        "skipLibCheck": true
    },
    "include": [
        "index.ts"
    ]
}

index.ts:

import * as K8s from 'k8s';

async function main() {
    const api = K8s.api({
        endpoint: 'http://localhost:8000'
        , version: '/api/v1'
    });

    console.log(await api.get('namespaces/default/pods'));
}

main().then(() => { }).catch((e) => console.error(e));

Steps to reproduce:

$ npm install
$ tsc

Expected behavior:

Compilation succeeds.

Actual behavior:

Compilation fails with errors about ignored library k8s:

node_modules/k8s/index.ts(5,23): error TS7006: Parameter 'conf' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(8,13): error TS7005: Variable 'Buffer' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(12,5): error TS7008: Member 'strictSSL' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(13,5): error TS7008: Member 'domain' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(14,5): error TS7008: Member 'auth' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(42,25): error TS7006: Parameter 'kubeconfig' implicitly has an 'any' type.
... etc
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 25, 2017

Sounds like k8s shouldn't be distributing .ts files - it should be distributing just the .js and .d.ts files instead.

@DanielRosenwasser DanielRosenwasser added the External Relates to another program, environment, or user action which we cannot control. label Apr 25, 2017
@sciolizer
Copy link
Author

I thought that might be the case. I can request a fix, but is there anything I can do about it in the meantime?

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 25, 2017

I opened up Goyoo/node-k8s-client#35 for you.

In the meantime, you could run a post-install step to produce the .d.ts files into a local ./src/types/k8s/, and use path mapping to resolve imports to "k8s" to those local .d.ts file.

So this could be your root tsconfig.json which is adjacent to your src:

{
  "compilerOptions": {
    "noImplicitAny": true,

    // ...
    "baseUrl": "./",
    "paths": {
      "*": ["src/types/k8s"]
    }
  }
}

And you could make a separate tsconfig.k8s.json which looks something like

{
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "./src/types/k8s"
  },
  "include": ["./node_modules/k8s/index.ts"]
}

@sciolizer
Copy link
Author

sciolizer commented Apr 25, 2017

The workaround works great, thanks!

@mhegazy
Copy link
Contributor

mhegazy commented May 19, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed May 19, 2017
@victornoel
Copy link

@DanielRosenwasser @mhegazy I'm not sure we should consider this fixed.

I understand that libraries shouldn't publish *.ts files, but sometimes, they just do, and we can't control every other library easily.
I think typescript should not try to apply this kind of setting (here noImplicitAny) to the node_modules simply because it is meant to be applied to the user code being compiled, not the external dependencies.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants