在尝试导入多种类型时,我遇到了Es-linting问题,
在RN项目中,我已经在项目中创建了多种数据类型
export type props = {
btnText: string,
colorType: number,
btnType: number,
onPress: Function,
btnStyle?: Object,
textStyle?: Object
}
export type buttonSubStyle = {
width: number,
height: number,
backgroundColor: string,
borderRadius?: number,
borderColor?: string
}
export type textSubStyle = {
color: string,
fontSize: number,
}
它们存在于datatTypes / buttonType.js
我正在将它们导入我的component / elements / button.js
import type {props, buttonSubStyle, textSubStyle} from "./../../dataTypes/buttonType"
const button = (props:props) => {
const TYPE_LARGE_ROUND = 1
const TYPE_SMALL_ROUND_OUTLINE = 2
const TYPE_SMALL_ROUND = 3
const TYPE_SMALL_FILTER = 4
const COLOR_BLUE = 1
const COLOR_WHITE = 2
const COLOR_GREEN = 3
const {btnStyle, textStyle, onPress, btnType, btnText, colorType} = props
let subStyle:buttonSubStyle = {
width: 300,
height: 50,
borderRadius: 20,
backgroundColor: theme.primaryBlue
}
let textSubStyle:textSubStyle = {
color: theme.primaryWhite
}
这里是说props
和textSubStyle
已定义但从未使用过,而buttonSubStyle
却没有任何问题
有人可以告诉我为什么会出现此错误吗?
这是我的陪同配置
{
"env": {
"browser": true,
"es6": true
},
"parser": "babel-eslint",
"extends": ["eslint:recommended", "plugin:react/recommended", "prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["react", "flowtype"]
}
答案 0 :(得分:0)
Eslint对开箱即用的流类型的支持有限。特定于流类型的规则flowtype/use-flow-type
应该可以解决您的问题。
https://github.com/gajus/eslint-plugin-flowtype#use-flow-type