具有以下内容:
tsconfig
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"jsx": "react",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"declaration": true,
"outDir": "lib",
"lib": ["es2015","dom"]
}
}
注意声明:true
和.tsx文件:
import * as styledComponents from "styled-components";
export const backColor = (props: MyProps) => props.theme.backColor;
export const Title = styledComponents.div`
text-align: center;
background-color:${backColor};
width: 100%;
`;
当我tsc
在终端上运行编译时,我得到:
错误 TS2339:类型“/root/node_modules/styled-comp ...”上不存在属性“div”。
更新
两种导入样式组件的方式都会发生错误
import styled from 'styled-components'
import * as styled from 'styled-components'