我只尝试在textAlign={'center'}
组件中使用简单的<TextInput/>
。它可以按预期工作,但打字稿一直抱怨该属性不存在。
代码直接来自官方文档
import React, { Component } from 'react';
import { TextInput } from 'react-native';
export default function UselessTextInput() {
const [value, onChangeText] = React.useState('Useless Placeholder');
return (
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={text => onChangeText(text)}
value={value}
/>
);
}
万一有人怀疑依赖关系,本机版本为0.62.2
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"@types/jest": "^24.9.1",
"@types/react": "^16.9.35",
"@types/react-native": "^0.60.31",
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.9.0",
"redux-devtools": "^3.5.0",
"typescript": "^3.9.3"
},
有人有同样的问题吗,不确定是打字稿错误还是我的打字稿配置有问题。
答案 0 :(得分:0)
DefinitelyTyped react-native index.d.ts中似乎缺少此道具的类型声明。
然而, style 属性textAlign
被声明并且似乎具有相同的行为。
<TextInput
style={{ textAlign: 'center' }}
...
/>