Reactjs 为什么;没有与此调用匹配的重载“;在react select中使用自定义样式时出现TypeScript错误?

Reactjs 为什么;没有与此调用匹配的重载“;在react select中使用自定义样式时出现TypeScript错误?,reactjs,typescript,react-select,Reactjs,Typescript,React Select,我正在尝试在我的typescript react应用程序中设置react select组件的样式,但没有成功。在跟踪文档时,我得到以下错误: No overload matches this call. Overload 1 of 2, '(props: Readonly<ReactSelectProps<string>>): ReactSelectClass<string>', gave the following error. Type '{

我正在尝试在我的typescript react应用程序中设置react select组件的样式,但没有成功。在跟踪文档时,我得到以下错误:

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

有人知道如何在typescript和react select中使用自定义样式吗?
谢谢。

您可以从“react”导入
cssprroperties
界面,并将返回值转换为
控件的
cssprroperties
键:

import React, { CSSProperties } from 'react'

const inputStyle = {
  control: () => ({
    width: 200,
  } as CSSProperties),
}
这是因为
control
styleFn
类型,它是:

type styleFn = (base: CSSProperties, state: any) => CSSProperties;

我相信你有一个输入错误:
Select
style
道具应该是
style
(复数)


style
(单数)属性通常应为
cssprroperties
类型。但是
styles
(复数)是一个具有返回
cssprroperties
的函数值的对象。因此,typescript正在帮助您,尽管有点神秘。

哦,我明白了,谢谢您,这就是示例文档中的做法!但是,我安装的Styles组件没有“Styles”属性。我今天早上安装了npm的react styles,所以我尝试了一个支持“styles”道具的版本。您知道如何获取/升级到支持它的版本吗@Garrett MotznerOdd,因为它在源代码atm中(版本3.1.0):。确保安装了正确的软件包并导入了正确的组件,我想。。。。至于
react-
样式
(与
react-select
相反),我不确定这是如何相互作用的。可能会删除它,直到它工作为止?@Sequinex如果你想为
react select
()安装打字,请执行以下操作:
npm i@types/react select
。但是你需要这些类型吗,@AjeetShah?如果你没有它们,它应该仍然有效。基本上(我认为)这不是一个打字问题。它不需要安装打字。但是安装打字有助于提前发现错误。它只是让开发变得更容易,没有别的。我想确保OP知道如何安装打字,安装与否是他们的选择。
import React, { CSSProperties } from 'react'

const inputStyle = {
  control: () => ({
    width: 200,
  } as CSSProperties),
}
type styleFn = (base: CSSProperties, state: any) => CSSProperties;