【问题标题】:how to solve the emotion problem with typescript and typescript如何用打字稿和打字稿解决情感问题
【发布时间】:2021-06-19 05:57:43
【问题描述】:

我正在尝试创建带有情感的标记,但它不起作用,我相信是因为打字稿,因为在 javascript 文件中它可以工作。有人知道怎么解决吗?

我的主题:

import '@emotion/react';

export const palette = {
  common: {
    black: '000',
    white: 'fff'
  }

我的组件:

    import styled from '@emotion/styled';
    
    import { theme } from '../../utils/theme';    
         

      export const button = styled.button`
           background: ${({ theme }) => theme.pallete.common.black};
        `;

错误:

Property 'pallete' does not exist on type 'object'

【问题讨论】:

  • 您正在导出 const palette,但您正在导入 theme,然后对 theme 什么都不做。

标签: reactjs typescript emotion


【解决方案1】:

你好像有错别字

Property 'pallete' does not exist on type 'object'

虽然名字是palette

尝试修改名称

【讨论】:

  • 你好,这里打错了,代码正确,错误还在继续
【解决方案2】:

您好,您可以像这样键入您的组件。


interface Pallete {
 common: {
   black: '#000'
 }
}
export const button = styled.button<{ pallete: Pallete }>`
  background: ${({ pallete }) => pallete.common.black};
`;

【讨论】:

    猜你喜欢
    • 2022-07-05
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 2017-09-26
    • 1970-01-01
    • 2017-04-11
    相关资源
    最近更新 更多