reactjs - 使用带有 typescript 的 injectGlobal 样式组件 API
问题描述
我正在尝试使用简单的 injectGlobal API,但无法使其与打字稿一起使用。我在 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
寻求任何建议!
解决方案
看起来这个错误来自tslint no-unused-expression rule。injectGlobal
您可以通过在您的 like 中添加allow-tagged-template
选项来免除对模板标签的调用,tslint.conf
例如:
{
"rules": {
"no-unused-expression": [true, "allow-tagged-template"]
// ...
}
}
推荐阅读
- amazon-web-services - aws Sagemaker 使用每个实例的实例指标自动扩展
- javascript - 将图标设置为将插入事件的元素
- python - 如何在 DataFrame 中分组并同时添加时间值
- android - TableLayout如何在ImageView之间添加间距
- angular - Angular Material Table 中的按钮不起作用
- ios - 根视图控制器的确切含义
- angularjs - 缩小后角度 ui-select 中断
- php - 将数据库结果存储到 PHP 中的变量中
- django - Django 管理员:postgres DateTimeRangeField 未正确显示
- c# - WPF .NET Core 3.1 应用程序发布单个文件(发布)失败