Tslint: `no-unsafe-any` with tsx throwing error

Created on 28 Jul 2017  ·  9Comments  ·  Source: palantir/tslint

Hi! Can't understand why.

CLI:

tslint -c tslint.json --type-check --project tsconfig.json src/app.tsx

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5", 
    "module": "commonjs",
    "lib": [
      "dom",
      "es2015"
    ],                                        
    "jsx": "react",                           
    "declaration": true,                      
    "sourceMap": true,                        
    "experimentalDecorators": true        
  }
}

Bug Report

  • __TSLint version__: 5.5.0
  • __TypeScript version__: 2.4.2
  • __Running TSLint via__: CLI

TypeScript code being linted

import * as React from 'react';

export class App extends React.Component<{}, {}> {
    public render(): JSX.Element {
        return <span/>;
    }
}

with tslint.json configuration:

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

Actual behavior

Error

ERROR: app.tsx[5, 17]: Unsafe use of expression of type 'any'.

Expected behavior

No errors

Fixed

Most helpful comment

I have the same problem

All 9 comments

Do you have @types/react installed? Are there any tsc errors when you compile your project with --noImplicitAny?

@adidahiya

Do you have @types/react installed

yes

npm ls @types/react
...
└── @types/[email protected]

Are there any tsc errors when you compile your project with --noImplicitAny?

no

I have the same problem

Can you try to repro this with the latest TSLint? We've had various refactorings occur since 5.5.0.

It's still reproducible (in my case)

The same problem

This was fixed by #3699. 🎉

For anyone that finds this in the future. I was struggling with this for over an hour while configuring eslint. After adding the types with yarn add -D @types/react @types/react-dom I was still getting an error on the return statement. This was fixed by simply reloading/restarting vscode. Save yourself some time and use F1 -> Reload Window.

🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

Was this page helpful?
0 / 5 - 0 ratings