【问题标题】:Flow JS isnt finding errors in JSX blocksFlow JS 没有在 JSX 块中发现错误
【发布时间】:2021-10-08 14:59:58
【问题描述】:

我有以下组件,我已将流类型标记添加到:

// @flow                                          
                                                            
import * as React from 'react';                             
                                                  
type UnauthorisedProps = {|                       
  message :string                                                  
|};                                                                       
                                                                          
export function Unauthorised(props :UnauthorisedProps) :* {               
  return (                                                               
    <div>                                                                 
      <div>{ props.message }</div>                                        
    </div>                                           
  );                                            
}

但是在使用 this 的地方,flow 没有捕捉到这个错误:

import { Unauthorised } from '../unauthorised/Unauthorised';
// @flow

function SomethingElse(props) {
    return (<Unauthorised mexssage={ props.message } );
}

我正在运行命令

yarn run flow check

它没有报告mexssage拼写错误的明显错误。

如果我将 UnauthorisedProps 定义更改为无效的内容,流程会报告错误,因此它正在查看代码。

【问题讨论】:

    标签: javascript reactjs react-redux flowtype


    【解决方案1】:

    在我的初始设置中有几个原因/缺少步骤。

    1. .flowConfig 需要这个自动值:

      [棉绒]

      [选项]

      +react.runtime=自动

    2. React 的导入需要从 import React from 'react'; 更改为

      从'react'导入*作为React;

    3. 需要的函数返回类型:React.Node

    然后它起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-30
      • 2022-01-11
      • 2015-09-03
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多