Z
Z
zwezew2019-04-08 17:30:12
typescript
zwezew, 2019-04-08 17:30:12

Why doesn't styled theme declaration fire when used in TyperScript?

Created a theme declaration following the example

// import original module declarations
import 'styled-components'

// and extend them!
declare module 'styled-components' {
  export interface DefaultTheme {
    borderRadius: string

    colors: {
      main: string
      secondary: string
    }
  }
}

and challenge
import { DefaultTheme } from 'styled-components'

const myTheme: DefaultTheme = {
  borderRadius: '5px',

  colors: {
    main: 'cyan',
    secondary: 'magenta',
  },
}

export { myTheme }

Next I used it
import { createGlobalStyle } from 'styled-components';

export const MyComponent = styled.div`
  borderRadius: ${props => props.theme.borderRadius};
`;

Judging by the comment // theme is now fully typed - variables must be defined in the theme declaration, nevertheless it gives an error
(parameter) props: any
Параметр "props" неявно имеет тип "any"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-08
@zwezew

Where is the theme declaration?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question