Using styled components with props and typescript

后端 未结 4 1982
眼角桃花
眼角桃花 2021-02-01 20:24

I\'m trying to integrate typescript into our project and so far I stumbled upon one issue with styled-components library

Consider this component

import *         


        
4条回答
  •  滥情空心
    2021-02-01 20:49

    You need only specify a interface:

    import { createGlobalStyle } from 'styled-components';
    
    interface PropsGlobalStyle {
      dark: boolean
    }
    
    export default createGlobalStyle`
      body {
        box-sizing: border-box;
        margin: 0;
        font-family: Arial, Helvetica, sans-serif;
        color: ${(props:PropsGlobalStyled) => (props.dark ? '#FFF' : '#000')};
    background-color: ${(props:PropsGlobalStyled) => (props.dark ? '#000' : '#FFF')};
      }
    `;
    

提交回复
热议问题