DefinitelyTyped:为现有组件添加新的道具类型 [英] DefinitelyTyped: Add new props typing for existing component
问题描述
是否可以在DefinitelyTyped
中为新的props
声明新的类型?我在SelectField
组件中用一些新的props
更新了material-ui
,但是在DefinitelyTyped
中的键入是旧的.我可以通过某种方式扩展SelectField
类型并添加新的props
类型吗?现在我有:
Is there any way to declare new typing for new props
within DefinitelyTyped
? I updated material-ui
with some new props
in SelectField
component, but typings in DefinitelyTyped
are old. Can I extend in some way SelectField
typing and add new props
types? Now I have:
<SelectField
multiple={true}
hintText="Select type"
value={[...this.state.values]}
onChange={this.onChange}
selectionRenderer={this.selectionRenderer}
>
我需要添加multiple?: boolean
和selectionRenderer: (values: any[]) => string
类型.我尝试declare module 'material-ui/SelectField' {}
,但不起作用.有任何想法吗?
And I need to add multiple?: boolean
and selectionRenderer: (values: any[]) => string
types. I tried to declare module 'material-ui/SelectField' {}
but it not works. Any ideas?
推荐答案
您应该可以使用模块扩充:
declare module "material-ui" {
interface SelectFieldProps {
multiple?: boolean;
selectionRenderer: (values: any[]) => string;
}
}
如您所见,语法与您尝试过的语法略有不同.
As you can see, the syntax is a bit sifferent than what you've tried.
如果在__MaterialUI
命名空间中定义了SelectFieldProps
,则此方法应该起作用:
If SelectFieldProps
is defined in the __MaterialUI
namespace, then this should work:
declare module "material-ui" {
namepsace __MaterialUI {
interface SelectFieldProps {
multiple?: boolean;
selectionRenderer: (values: any[]) => string;
}
}
}
这篇关于DefinitelyTyped:为现有组件添加新的道具类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!