Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-unsafe-any raises errors on import statements that are not typed as "any" #2494

Closed
lddubeau opened this issue Apr 4, 2017 · 2 comments
Closed

Comments

@lddubeau
Copy link

lddubeau commented Apr 4, 2017

Bug Report

  • TSLint version: 5.0.0
  • TypeScript version: 2.2.2
  • Running TSLint via: CLI: tslint test.ts --type-check --project tsconfig.json

TypeScript code being linted

import * as ts from "typescript";

// Prevent TypeScript from complaining about ts being unused.
console.log(ts.getCommentRange);

with tslint.json configuration:

{
    "rules": {
        "no-unsafe-any": true
    }
}

I've tried with the following two tsconfig.json:

{
  "compilerOptions": {}
}

and:

{
  "compilerOptions": {
    "rootDir": ".",
    "noEmitOnError": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "skipDefaultLibCheck": true,
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "target": "es5"
  }
}

Actual behavior

The error:

test.ts[1, 21]: Unsafe use of expression of type 'any'.

Expected behavior

No error. I don't see why the imported symbols are somehow considered to be of type any. They obviously aren't since the IDE is able to perform completion that uses TypeScript type information.

@amatiasq
Copy link

Same issue here: it warns for every expression at the first line of each method

ERROR: src/pathfinding/pathfinding.spec.ts[16, 12]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[16, 12]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[16, 12]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[16, 35]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[16, 12]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[16, 12]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[20, 22]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[20, 22]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[20, 22]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[20, 45]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[20, 22]: Unsafe use of expression of type 'any'.
ERROR: src/pathfinding/pathfinding.spec.ts[20, 22]: Unsafe use of expression of type 'any'.
[...]

This is the code it's complaining about:

screenshot

@adidahiya
Copy link
Contributor

this should be fixed in tslint >=5.1.0, can you try that out?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants