Reactjs Can';不要对带有情感js和类型脚本的样式化组件使用道具

Reactjs Can';不要对带有情感js和类型脚本的样式化组件使用道具,reactjs,typescript,styled-components,emotion,emotion-js,Reactjs,Typescript,Styled Components,Emotion,Emotion Js,下面是我非常简单的组件: import React,{ReactChild,ElementType}来自“React” 从“@emotion/styled”导入样式 类型WrapperPropsType={ 大小?:大小类型 } 类型按钮打印类型={ as?:元素类型, 大小?:大小类型, 儿童?:儿童 } const Wrapper=styled.button((props:WrapperPropsType)=>({ fontSize:fontSize[props.size], })) 常量按

下面是我非常简单的组件:

import React,{ReactChild,ElementType}来自“React”
从“@emotion/styled”导入样式
类型WrapperPropsType={
大小?:大小类型
}
类型按钮打印类型={
as?:元素类型,
大小?:大小类型,
儿童?:儿童
}
const Wrapper=styled.button((props:WrapperPropsType)=>({
fontSize:fontSize[props.size],
}))
常量按钮=({as,size,children}:ButtonPropsType)=>{
返回(
{儿童}
)
}
我的
.tsconfig

{
“编译器选项”:{
“类型”:[“节点”、“@emotion/react”],
“宣言”:正确,
“declarationDir”:“构建”,
“模块”:“esnext”,
“目标”:“es5”,
“源地图”:正确,
“jsx”:“保存”,
“moduleResolution”:“节点”,
“allowSyntheticDefaultImports”:true,
“esModuleInterop”:true
},
“包括”:[“src/***”],
“排除”:[
“节点_模块”,
“建造”,
“src/***.test.tsx”
]
}
但在编译时,我得到了下一个错误:

错误:src/components/Button/Button.tsx(18,30):语义错误TS2339:类型“{theme?:theme;as?:ElementType;}”上不存在属性“size”&Pick &{…;}

我做错了什么?谢谢你的帮助

软件包版本:
@emotion/react
版本:11.1.2
@emotion/styled
版本:11.0.0
typescript
version:4.1.3

您已在
WrapperPropsType
中定义了
size
,但未使用它。加上它,它就会工作

const Button = ({ as, size, children }: ButtonPropsType & WrapperPropsType) => {

我设法解决了这个问题,用
@rollup/plugin-typescript
替换了
rollup-plugin-typescript2
。代码中没有错误。

我在ButtonPropsType中也有
大小
,因此它已经定义,添加
&WrapperPropsType
不会改变任何东西,不幸的是,请检查您是否使用了正确的
ButtonPropsType
。Coz
{theme?:theme;as?:ElementType;}选择(&Pick)