我希望引數物件的“選項”屬性至少包含“標簽”屬性。
我試過自己做,但它不會編譯。
interface BaseOptionType {
label: string;
}
interface CreatableAutoCompleteProps<OptionType extends BaseOptionType> {
name?: string;
options: OptionType;
}
const CreatableAutoComplete = <_OptionType,>({
name,
options,
}: CreatableAutoCompleteProps<_OptionType>): number => {
return 0;
};
export default CreatableAutoComplete;
我收到以下錯誤。
(type parameter) _OptionType in <_OptionType>({ name, options, }: CreatableAutoCompleteProps<_OptionType>): number
Type '_OptionType' does not satisfy the constraint 'BaseOptionType'.ts(2344)
那么,這樣做的正確方法是什么。
uj5u.com熱心網友回復:
型別“_OptionType”不滿足約束“BaseOptionType”
好吧,我認為您只需要進行_OptionTypeextend BaseOptionType。
const CreatableAutoComplete = <_OptionType extends BaseOptionType,>({
name,
options,
}: CreatableAutoCompleteProps<_OptionType>): number => {
return 0;
};
操場
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/466984.html
