Skip to content

noImplicitAny checks node_modules despite skipLibCheck #15363

Closed

Description

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

Activity

  1. DanielRosenwasser commented on Apr 25, 2017

    @DanielRosenwasser
    Member

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

  2. sciolizer commented on Apr 25, 2017

    @sciolizer
    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?

  3. DanielRosenwasser commented on Apr 25, 2017

    @DanielRosenwasser
    Member

    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"]
    }
  4. sciolizer commented on Apr 25, 2017

    @sciolizer
    Author

    The workaround works great, thanks!

  5. mhegazy commented on May 19, 2017

    @mhegazy
    Contributor

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

  6. victornoel commented on Jun 19, 2017

    @victornoel

    Daniel Rosenwasser (@DanielRosenwasser) Mohamed Hegazy (@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.

  7. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions