@typesstyled-components返回type any而不是StyledComponent。预期的行为?

问题描述 投票:0回答:1

如果我使用 @types/styled-components 4.4.1或更高版本,我的所有样式组件的类型从 StyledComponentany. 这是预期的行为吗?

我目前使用的是 [email protected]但我在使用最新版本和类型声明时遇到了同样的问题。

import styled from "styled-components";

const ErrorMessage = styled.label`
  color: red;
  font-size: 16px;
  font-weight: 600;
`; // any
reactjs typescript typescript-typings styled-components
1个回答
0
投票

如果有人遇到同样的问题,我想把我的发现公布出来。我安装的一个依赖项 hoist-non-react-statics@2 导致错误的 @types/styled-components v4.1.1及以上。

运行 npm i --save-dev @types/hoist-non-react-statics@3 为我修好了。

© www.soinside.com 2019 - 2024. All rights reserved.