【发布时间】:2019-02-23 06:44:10
【问题描述】:
我正在尝试使用简单的 injectGlobal API,但无法使其与 typescript 一起使用。我在 theme.tsx 中有以下设置
import * as styledComponents from "styled-components";
import { ThemedStyledComponentsModule } from "styled-components";
import IThemeInterface from "./theme";
const {
default: styled,
css,
injectGlobal,
keyframes,
ThemeProvider
} = styledComponents as ThemedStyledComponentsModule<IThemeInterface>;
export default styled;
export { css, injectGlobal, keyframes, ThemeProvider };
在我的 App.tsx 中我只是这样做
import { injectGlobal} from '../theme.tsx'
尝试正常使用却总是出现如下错误
unused expression, expected an assignment or function call
寻求任何建议!
【问题讨论】:
-
报错的代码是哪一行?
-
@MattMcCutchen 错误出现在我打电话给
injectGlobal` * { margin: 0; padding: 0; } `; -
附注给来自未来的任何其他读者:
injectGlobal在 V4 中发布此帖子三周后是 deprecated,并被createGlobalStyle取代
标签: reactjs typescript styled-components