React $ Node未定义

时间:2019-11-21 03:28:29

标签: reactjs eslint flowtype

enter image description here

我创建了一个新的RN项目。这个警告显示出来了。 我将Flow和eslint用于该项目。而且我知道React$Node是什么意思。但我不知道为什么会显示此警告。因为我认为React已经定义了它。

这是我的.eslintrc.js

module.exports = {
  parser: 'babel-eslint',
  extends: ['airbnb', 'prettier', 'prettier/react', 'prettier/flowtype'],
  plugins: ['react', 'flowtype', 'jsx-a11y', 'import', 'react-native'],
  rules: {
    'react/jsx-filename-extension': [1, {extensions: ['.js', '.jsx']}],
    'react/prefer-stateless-function': [2, {ignorePureComponents: true}],
    'react/forbid-prop-types': [0, {forbid: []}],
    'import/extensions': [1, 'never', {svg: 'always', json: 'always'}],
    'import/no-extraneous-dependencies': [
      'error',
      {
        devDependencies: true,
        optionalDependencies: false,
        peerDependencies: false,
      },
    ],
    semi: ['error', 'never'],
  },
  env: {
    jest: true,
    browser: true,
  },
}

2 个答案:

答案 0 :(得分:1)

我将此添加到了extends中。 "plugin:flowtype/recommended"。这样就行了!

module.exports = {
  parser: 'babel-eslint',
  extends: [
    'airbnb',
    'prettier',
    'prettier/react',
    'prettier/flowtype',
    'plugin:flowtype/recommended',
  ],
  plugins: ['react', 'flowtype', 'jsx-a11y', 'import', 'react-native'],
  rules: {
    'react/jsx-filename-extension': [1, {extensions: ['.js', '.jsx']}],
    'react/prefer-stateless-function': [2, {ignorePureComponents: true}],
    'react/forbid-prop-types': [0, {forbid: []}],
    'import/extensions': [1, 'never', {svg: 'always', json: 'always'}],
    'import/no-extraneous-dependencies': [
      'error',
      {
        devDependencies: true,
        optionalDependencies: false,
        peerDependencies: false,
      },
    ],
    semi: ['error', 'never'],
  },
  env: {
    jest: true,
    browser: true,
  },
}


Recommended Configuration

答案 1 :(得分:0)

使用时出现相同错误

const TProps = {
    children: React$Node
}

代替

type TProps = {
    children: React$Node
}