Typescript styled-component error: “Type '{ children: string; }' has no properties in common with type 'IntrinsicAttributes'.”

后端 未结 3 910
轻奢々
轻奢々 2020-12-19 08:33

Getting a typescript error on my styled-component

Type \'{ children: string; }\' has no properties in common with type \'IntrinsicAttributes\'.ts(2559

相关标签:
3条回答
  • 2020-12-19 09:12

    Ok like it was stated above just to clarify if you create a component

       <DeliverNow>
    
            </DeliverNow>
    

    it automatically passes props to it and if when u declare it

    const DeliverNow = () => {}
    

    Typescript would tell you that they don't match cuz, in reality, DeliverNow takes in some props

    so in actual sense, its meant to be

    const DeliverNow = (props:any) => {}
    
    0 讨论(0)
  • 2020-12-19 09:21

    I got this error:

    Type '{ children: string; }' has no properties in common with type 'IntrinsicAttributes'.ts

    When dynamically added tags in my react application. I found a great solution that has nothing to do with typescript or styled-components.

    It is enough to create a node through React.createElement

    For example:

    const Title: React.SFC<TitleProps> = ({ tag, styled, children }) =>
      React.createElement(tag, { ...styled }, children);
    
    const TitleStyled = styled(Title)`Your styled`
    
    0 讨论(0)
  • 2020-12-19 09:28

    <Note>{props.message}</Note> is same as Note({ children: props.message }) so typescript is complaining that function Note doesn't take any arguments and function type doesn't match. It has nothing to do with styled-components.

    (IntrinsicAttributes is probably the default interface you extend when you write a functional component. Or something like that idk xD)

    My best guess is you want const Note = props.error ? NotificationError : NotificationSuccess; instead of what you have written.

    PS. I might be wrong but I'm mostly sure this is the case.

    0 讨论(0)
提交回复
热议问题