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";
添加回答
舉報