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

S2786: 'View' cannot be used as a JSX component. #15802

Closed
1 task
ksielyov opened this issue Apr 23, 2022 · 14 comments
Closed
1 task

S2786: 'View' cannot be used as a JSX component. #15802

ksielyov opened this issue Apr 23, 2022 · 14 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects

Comments

@ksielyov
Copy link

Environment

Node version: v14.17.5
npm version: v7.21.1
Local ESLint version: v8.14.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 21.1.0

What parser are you using?

@typescript-eslint/parser

What did you do?

Configuration
{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:prettier/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint"
    ],
    "rules": {
        "@typescript-eslint/ban-ts-comment": "off",
        "prettier/prettier": "error"
    },
    "globals": {
        "__DEV__": true
    }
}
import React from 'react';
// @ts-ignore
import DoubleBounce from 'react-native-loader';
import {View} from 'react-native';

const DoubleBounceLoader: React.FC = () => (
  <View>
    <DoubleBounce size={16} color="#3A3A3A" />
  </View>
);

export default DoubleBounceLoader;

What did you expect to happen?

Working eslint configuration

What actually happened?

TS2786: 'View' cannot be used as a JSX component.   Its instance type 'View' is not a valid JSX element.     The types returned by 'render()' are incompatible between these types.       Type 'import("/Users/mikhailkiselyov/WebstormProjects/publife/node_modules/@types/react-native/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.         Type '{}' is not assignable to type 'ReactNode'.

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

@ksielyov ksielyov added bug ESLint is working incorrectly repro:needed labels Apr 23, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Apr 23, 2022
@ksielyov ksielyov changed the title Bug: (fill in) S2786: 'View' cannot be used as a JSX component. Apr 23, 2022
@aladdin-add
Copy link
Member

seems the error was from ts, not eslint?

@mdjermanovic
Copy link
Member

TS2786: 'View' cannot be used as a JSX component.

This error is coming from TypeScript, not ESLint.

Maybe these recent discussions could be helpful:

DefinitelyTyped/DefinitelyTyped#59839

https://stackoverflow.com/questions/71831601/ts2786-component-cannot-be-used-as-a-jsx-component

Triage automation moved this from Needs Triage to Complete Apr 23, 2022
@TalhaBlueEast
Copy link

I'm facing the same issue about this error. I add the below code to my package.json file.

"resolutions": {
  "@types/react": "17.0.2",
  "@types/react-dom": "17.0.2",
  "graphql": "^16.5.0"
},

Then, Run yarn install on a terminal.

It works for me.

@mcjambi
Copy link

mcjambi commented Aug 5, 2022

i have the same issue, not really an error, but make me confuse!

@fahad0samara
Copy link

I have the same problem

@NilsBaumgartner1994
Copy link

Same

@DianSSIE
Copy link

DianSSIE commented Aug 9, 2022

I had to just make sure the version numbers for:
"@types/react" x.x.x
and
"@types/react-native" y.y.y

match with:
"react": x.x.x
and
"react-native" y.y.y

@ZackKuhn
Copy link

ZackKuhn commented Aug 17, 2022

  1. Paste in package.json file:
    "resolutions": { "@types/react": "17.0.14", "@types/react-dom": "17.0.14" },
  2. Run yarn install on terminal.

@DJ-Icebear
Copy link

For me the issue was I was importing types explicitly when not needed:
I removed two lines from the package.json:

 "@types/react": "~18.0.0",
 "@types/react-native": "~0.69.1",

@Rafael-Santos-DV
Copy link

I added the following dependencies and it solved the problem:

"@types/react-dom": "17.0.14",
"@types/react": "~18.0.0",
"@types/react-native": "~0.69.1",

@juancsaenz
Copy link

I had to just make sure the version numbers for: "@types/react" x.x.x and "@types/react-native" y.y.y

match with: "react": x.x.x and "react-native" y.y.y

It solved my problem, thank you.

@GtechHardik
Copy link

for me there was wrong version of type script
so
npm install --save-dev @types/react @types/react-dom @types/react-native

solved the issue

@BrianIto
Copy link

To add more to this specific topic, I was having this problem with every React Native Built-In Component (like View, ScrollView, TouchableOpacity, etc.);

  • Updating to matching types versions didn't worked;
  • Removing the explicit @types for react, react-native, react-dom also didn't worked;

for me what solved was @GtechHardik below suggestion:

for me there was wrong version of type script so npm install --save-dev @types/react @types/react-dom @types/react-native

solved the issue

#15802 (comment)

@kosbog
Copy link

kosbog commented Oct 20, 2022

for me there was wrong version of type script so npm install --save-dev @types/react @types/react-dom @types/react-native

solved the issue

Perfect solution! Thanks!

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Oct 21, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests