segmentio / evergreen

🌲 Evergreen React UI Framework by Segment
https://evergreen.segment.com
MIT License
12.39k stars 832 forks source link

Missing Theme interface (Typescript error) #1209

Closed thiagomdo1 closed 2 years ago

thiagomdo1 commented 3 years ago

Hi. I'm getting a Typescript error for defaultTheme props: Property 'fontSizes' does not exist on type '{}'. TS2339

It seems the problem is in the index.d.ts file:

export interface Theme {}
export const defaultTheme: Theme
export const classicTheme: Theme

My version: 6.0.1

raffaeu commented 3 years ago

Same for me, if you do not export the types, we cannot do this :

    const theme = {
        ...defaultTheme,
        components: {
            ...defaultTheme.components,
        Button: {

        }
    }
krijoh92 commented 3 years ago

If you need a workaround for now, you can create a evergreen.d.ts in your src folder, and use this:

import 'evergreen-ui';
import { YourCustomThemeType } from './types/evergreen-theme';

declare module 'evergreen-ui' {
  export interface Theme extends CustomTheme {
  }
}

Personally I've created a theme by console.logging the default theme and then using a json to typescript converter, and just editing some parts. It's better than nothing for now

brandongregoryscott commented 2 years ago

For anyone following this issue, v6.7.0 provides a strongly typed DefaultTheme interface that should help 😄