3 回答

TA贡献1847条经验 获得超11个赞
您可以将类型显式声明为:
import React, { ComponentProps } from 'react';
import { Input } from 'reactstrap';
interface IconInputProps {
type: ComponentProps<typeof Input>['type'];
// ...
}
这会传递特定组件 prop 的类型声明,即使给定的库/组件未导出该类型,它也会起作用。
但有一些注意事项:
不适用于静态声明的默认道具和通用道具
来源:https ://github.com/piotrwitek/react-redux-typescript-guide#reactcomponentpropstypeof-xxx

TA贡献1803条经验 获得超3个赞
您可以尝试扩展InputProps您应该从中导入的内容@types/reactstrap(我猜它有类型)
在您的界面中,只需添加InputProps. 所以你可以删除type, name 等等。所以你的代码看起来像
interface IIconInputProps extends InputProps {
label: string,
errorMessage: string,
icon: string
}
另外我建议名称以 开头interface,I这样你就知道它是一个接口。

TA贡献1820条经验 获得超9个赞
type: string
应替换为type: InputType
并且不要忘记导入这个import { InputType } from "reactstrap/lib/Input.d";
添加回答
举报