【发布时间】:2020-03-29 11:30:46
【问题描述】:
我目前正在接受我的组件的接口,它接受数组对象“选项”作为其参数之一。我的问题是如何为数组对象创建接口。我相信您需要对接口使用索引签名,但我之前没有使用过,不知道它需要如何结构。
目前我使用箭头功能。这是我声明函数接口的方式
interface IOption {
key: number;
text: string;
value: number
}
Interface DropDownInputInt {
name: string;
value: any;
label: string;
disabled: boolean;
onChange: Function;
extraClassName: string;
required: boolean;
options: IOption[] | string;
multiple: boolean;
clearable: boolean;
index?: number;
placeholder: string;
toolTipMessage: string;
addCollon: boolean;
}
const DropDownInput = ({
name,
value,
label,
disabled,
onChange,
extraClassName,
required,
options,
multiple,
clearable,
index,
placeholder,
toolTipMessage,
addCollon
}: DropDownInputInt) => {
//MY CODES HERE
})
我的第二个问题是如何在接受字符串和对象的接口中创建。
【问题讨论】:
-
你能澄清一下问题是什么吗?对象数组将是
Array<IOption>或IOption[]typescriptlang.org/docs/handbook/basic-types.html
标签: javascript reactjs typescript