【问题标题】:react native typescript, property 'textalign' does not exist on the type textinput反应本机打字稿,文本输入类型上不存在属性'textalign'
【发布时间】:2020-05-23 06:59:27
【问题描述】:

我只是在<TextInput/> 组件中尝试简单的textAlign={'center'}。它按预期工作,但打字稿一直抱怨该属性不存在。

代码直接来自官方文档

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}
    />
  );
}

如果有人想知道依赖关系,react-native 版本是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"
  },

有没有人有同样的问题,不确定是打字稿错误还是我的打字稿配置有问题。

【问题讨论】:

    标签: javascript typescript react-native


    【解决方案1】:

    DefinitelyTyped react-native index.d.ts 中似乎缺少此道具的类型声明。

    但是 style 属性 textAlign 已声明并且似乎具有相同的行为。

    <TextInput
      style={{ textAlign: 'center' }}
      ...
    />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-18
      • 2018-03-27
      • 1970-01-01
      • 2020-11-10
      • 1970-01-01
      • 2022-11-04
      • 2019-05-05
      • 2017-03-02
      相关资源
      最近更新 更多