对于我的组件,我需要从外部传递inputmode
作为props
。<input inputMode=<valid values>>
的有效值在React类型(node_modules@types React index.d.ts)中定义为
interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
[..]
// Living Standard
/**
* Hints at the type of data that might be entered by the user while editing the element or its contents
* @see https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute
*/
inputMode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search';
[..]
}
有没有办法在我的Props
接口中引用这个可能的值列表,而不复制所有可能的值,这些值在将来可能过时?
interface Props {
inputmode: <how to use the allowed values defined in the React types>;
}
你可以这样声明一个类型。
interface Props {
inputmode: HTMLAttributes['inputMode'];
}