Ошибка React.Fragment в коде Visual Studio - PullRequest
0 голосов
/ 11 мая 2019

Несмотря на то, что он работает, код Visual Studio продолжает отображать ошибку, как на скриншоте ниже.AFAIK, мой ESLint, кажется, не понимает около React.Fragment.Он отображает ошибку для любого <React.Fragment> или <Fragment>, который у меня есть.

Как отключить или исправить это?

Это проект с электронной реакцией, с машинописью.Я начал этот проект с

electron-forge init my-new-project --template=react-typescript

, затем обновил свои пакеты react, @types/react, @types/react-dom и react-dom до их последней версии, так как мне нужен компонент <Fragment>.Фрагмент - это новая функция, представленная React 16.xx

Вот мой текущий package.json:

"dependencies": {
    "@fortawesome/fontawesome-free": "^5.7.2",
    "@types/prop-types": "^15.7.1",
    "@types/react": "^16.8.17",
    "@types/react-dom": "^16.8.4",
    "electron-compile": "^6.4.4",
    "electron-devtools-installer": "^2.2.4",
    "electron-squirrel-startup": "^1.0.0",
    "electron-stylus": "^0.1.1",
    "ionicons": "^4.5.5",
    "moment": "^2.24.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-hot-loader": "^3.1.3",
    "tslib": "^1.9.3"
  },
  "devDependencies": {
    "babel-plugin-transform-async-to-generator": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "electron": "^5.0.1",
    "electron-forge": "^5.2.4",
    "electron-prebuilt-compile": "4.0.0",
    "tslint": "^5.16.0",
    "typescript": "^2.2.2"
  }

Я использую VSCode 1.33.1 на 64-битной машине Debian, ESLint 1.8.2

код ошибки:

JSX element type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | null' is not a constructor function for JSX elements.
  Type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>' is not assignable to type 'Element'.
    Types of property 'type' are incompatible.
      Type 'string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
        Type '(props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
          Type '(props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null' is not assignable to type 'StatelessComponent<any>'.
            Type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | null' is not assignable to type 'ReactElement<any>'.
              Type 'null' is not assignable to type 'ReactElement<any>'.ts(2605)

error in visual studio code

Дополнительное примечание: Когда я импортирую Fragment как отдельную переменную с:

import * as React from "react";
import { Fragment } from 'react' 

и затем попытайтесь вызвать компонент <Fragment>, он по-прежнему выдает ту же ошибку

...