在将 StyledComponents 与 ThemeProvider 一起使用时,我无法获得正确的类型。
我用这种方法尝试过:https : //github.com/styled-components/styled-components/issues/1589
到目前为止我的代码:
应用程序.tsx
import * as React from "react";
import "./styles.css";
import theme from "./theme";
import { ThemeProvider } from "styled-components";
import StyledButton from "./StyledButton";
export default function App() {
return (
<ThemeProvider theme={theme}>
<div className="App">
<StyledButton variant="primary">MyButton</StyledButton>
</div>
</ThemeProvider>
);
}
Run Code Online (Sandbox Code Playgroud)
主题.ts
import "styled-components";
const theme = {
borderRadius: "0.7rem",
color: "yellow"
};
export default theme;
Run Code Online (Sandbox Code Playgroud)
StyledButton.tsx
import styled from "styled-components";
interface IButtonProps {
color: string;
backgroundColor: string;
borderRadius?: string;
} …Run Code Online (Sandbox Code Playgroud)