【问题标题】:Typescript reactjs Can't spread props to input tagTypescript reactjs无法将道具传播到输入标签
【发布时间】:2019-06-21 12:05:29
【问题描述】:

我有一个可在整个应用程序中使用的可重用输入组件

import * as React from 'react';
import styles from "./Input.module.css";

interface Props {
  input: Object;
  label: string;
  custom: Object;
  meta: {
    touched: boolean;
    error: boolean;
  }
}

    const Input: React.SFC<Props> = ({
      input,
      label,
      custom,
    }) => (
        <div className={styles.container}>
          <input {...input} {...custom} />
          <span className={styles.highlight} />
          <span className={styles.bar} />
          <label>{label}</label>
        </div>
      );

    export default Input;

我正在将一个旧的 javascript 项目从 javascript 转换为 typescript。一切正常,除了当我将道具传播到输入标签中时,打字稿返回此错误。

知道是什么导致了错误吗?

【问题讨论】:

    标签: reactjs typescript jsx spread-syntax


    【解决方案1】:

    javascript 对象类型具有“isPropertyOf”、“hasOwnValue”等不适合输入元素的属性, 尝试更改为:

     input: {
    test: string,
    id: Number
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      相关资源
      最近更新 更多