首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能在没有引用的情况下命名类型

不能在没有引用的情况下命名类型
EN

Stack Overflow用户
提问于 2022-04-28 10:03:48
回答 1查看 3.6K关注 0票数 4

我的项目的设置是tsdx (基于RollupTypescript)。

在我的IDE (vscode)中工作一切看起来都很好,甚至运行yarn tsc也没有错误。

当我运行yarn build (即tsdx build)时,会得到以下错误:

代码语言:javascript
复制
(typescript) Error: /home/me/dev/app/src/components/alert/Alert.tsx(36,7): semantic error TS2742: The inferred type of 'AlertContainer' cannot be named without a reference to '@emotion/serialize/node_modules/csstype'. This is likely not portable. A type annotation is necessary.
Error: /home/me/dev/app/src/components/alert/Alert.tsx(36,7): semantic error TS2742: The inferred type of 'AlertContainer' cannot be named without a reference to '@emotion/serialize/node_modules/csstype'. This is likely not portable. A type annotation is necessary.

错误中引用的代码是:

代码语言:javascript
复制
type AlertContainerProps = {
  theme: any
};
const AlertContainer = styled(animated.div)<AlertContainerProps>`
  ${(props) => props.theme.primaryView}
  ...
`;

...

type AlertContentProps = Pick<React.ComponentProps<typeof AlertContainer>, 'style'> & {
  status?: string
};

我做错了什么?我怎么才能修好它?

我尝试了解决方案,但没有成功。

EN

回答 1

Stack Overflow用户

发布于 2022-10-06 11:04:56

这帮了我

代码语言:javascript
复制
import { StyledComponent } from '@emotion/styled';
import type { BoxProps } from '@mui/material/Box';
import Box from '@mui/material/Box';
import { styled } from '@mui/material/styles';

export const BoxStyled: StyledComponent<BoxProps> = styled(Box)(({ theme }) => ({ .......
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72041763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档