我试图在我的打字稿react应用程序中设置我的react select组件的样式,但没有成功。当遵循文档:https://react-select.com/styles#provided-styles-and-state时,出现以下错误:
No overload matches this call.
Overload 1 of 2, '(props: Readonly<ReactSelectProps<string>>): ReactSelectClass<string>', gave the following error.
Type '{ control: () => { width: number; }; }' has no properties in common with type 'CSSProperties'.
Overload 2 of 2, '(props: ReactSelectProps<string>, context?: any): ReactSelectClass<string>', gave the following error.
Type '{ control: () => { width: number; }; }' has no properties in common with type 'CSSProperties'. TS2769
代码示例:
const inputStyle = {
control: () => ({
width: 200,
}),
<Select
name="Name"
options={options}
style={inputStyle}
/>
任何人都知道如何对打字稿使用自定义样式并做出选择反应?谢谢。
您可以从'react'导入CSSProperties
接口,并将重新运行值转换为CSSProperties
:
import React, {CSSProperties} from 'react'
control: () => ({
width: 200,
} as CSSProperties)