reactjs - 如何在情感中键入 css 主题的道具
问题描述
我正在使用情绪,并做出反应。
我正在定义一个主题,并尝试在我的组件中使用它。
问题是,没有输入来自 css 的道具:
const ButtonA = styled('button')`
background-color: ${props => props.theme.color}; <= no type
`
css={theme => ({ marginRight: theme.spacing })} <= no type
我遇到了这个问题,并尝试环顾四周。 https://github.com/emotion-js/emotion/issues/1197
我做了以下emotion.d.ts
import '@emotion/react';
import '@emotion/core';
declare global {
namespace Emotion {
export interface Theme {
gap: {
XL: string;
L: string;
M: string;
S: string;
XS: string;
};
colors: {
white: string;
background: string;
border: string;
success: string;
font: string;
};
size: {
button: {
width: {
MIN: string;
};
height: {
M: string;
};
};
};
}
}
}
declare module '@emotion/core' {
export interface Theme {
gap: {
XL: string;
L: string;
M: string;
S: string;
XS: string;
};
colors: {
white: string;
background: string;
border: string;
success: string;
font: string;
};
size: {
button: {
width: {
MIN: string;
};
height: {
M: string;
};
};
};
}
}
在类型根中添加
"typeRoots": ["./src/types", "node_modules/@types"],
但仍然没有输入任何内容。我错过了什么?
解决方案
推荐阅读
- swift - CoreData:相同查询的不同执行时间
- google-chrome - 人脸 API 人脸 CORS 错误。有人解决它请
- xml - sxd-document / sxd-xpath 无法解析 XML
- go - GoLang 接口名称及其方法数量的规则
- c# - C# 系统命名空间 - 为什么我需要导入它?
- sql-server - cte1 是无效的对象名称
- xml - SaxonEE:9.8 ClassNotFoundException:执行 saxonValidator.validate 时 AtomicTypeValidator
- bash - 从枚举的文件名中减去数字
- c# - 为什么没有过滤数据库中的数据?
- sqlite - 在新的应用程序版本中替换数据库