'Property does not exist on type Theme from Emotion
I faced with a problem. When i try to read some parameters from theme-object, or destruсt it - i got an error
Property 'X' does not exist on type 'Theme'.
I created types.d.ts file, and added it there, but it doesn't help.
import '@emotion/react';
import { themeConfig } from './lib/theme';
declare module '@emotion/react' {
export interface Theme extends themeConfig {}
}
Code of my "custom-provider"
// Import modules
import React from 'react';
import {
css,
Global,
Theme,
ThemeProvider
} from '@emotion/react';
// Init Theme Config
export const themeConfig = {
typography: {...},
palette: {...}
};
interface Props {
theme: Theme;
}
// Create custom ThemeProvider
export const Provider: React.FC<Props> = ({ children, theme = themeConfig }) => (
<ThemeProvider theme={ theme }>
<Global
styles={(theme) => {
console.log(theme.palette); <- Here an error
return css``;
}}
/>
{ children }
</ThemeProvider>
);
UPD:
Solved the problem with change types.d.ts like this
type ThemeConfig = typeof themeConfig;
declare module '@emotion/react' {
export interface Theme extends ThemeConfig {}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
