question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Types: Missing overload for default export from @emotion/styled ?

See original GitHub issue

The problem

I wanted to generate types for rebass modules using the existing js files (for more details read the Additional Context section). But the way the rebass lib uses @emotion/styled doesnā€™t seem to be supported by the current types, when running tsc --declaration (with some other basic configuration to get everything together) the following error is reported:

src/index.js:50:28 - error TS2769: No overload matches this call. ...

I would love be able to add the missing overload to the types, but after looking at the nested modules the are involved I was kinda lost when reaching https://github.com/emotion-js/emotion/blob/master/packages/serialize/src/index.js#L342

My understanding of the argument types passed to styled in @rebass/reflexbox are

styled(
  string, // referring to one of JSX.IntrinsicElements keys
  propsToMerge // seems to be quite generic but has an impact on the props of the resulting component?
)(
  defaultPropsToBeTransformed // just a guess here, didn't check emotion code about it
  ...transformers // tons of functions 
  // looks like they are executed in the given order 
  // to modify the props after merging and before passing them to rendering?
)

Maybe these transformers are of type FunctionInterpolation but the allowed types would be Interpolation (from the same file)?

Proposed solution

Adding the missing overload to the types.

Alternative solutions

Help me to understand/find the related documentation so I can create a PR.

Additional context

The types for the main rebass module are ā€œonlyā€ existing in DefinitelyTyped, are incomplete and hardly maintained and the types for other @rebass/* modules donā€™t exist as far as I know.

So I wanted to experiment if there is a(n ā€œeasyā€) way to create and maintain the types by generating the definition files from the js source files. Itā€™s possible to do that and since the underlying modules all offer types I was quite hopefull.

On the lowest level of rebass is @rebass/reflexbox so I started with it. (I pushed my changes to my fork: https://github.com/karfau/rebass/tree/generating-types)

Potentially related issues (Iā€™m not sure):

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
Andaristcommented, Nov 26, 2019

While digging into it Iā€™ve even encountered:

Type ā€˜CSSObjectā€™ is not assignable to type ā€˜CSSObjectā€™.

šŸ˜…

That got me to realize there are 2 conflicting versions of csstype. I believe that last part (that props => props.css) should be rather easily typeable - itā€™s not any weird pattern. I need to analyze how our current typings are structured to fix this though, probably need to draw a dependency tree for them to see what depends on what and what is supposed to be used where. I donā€™t think this is that hard to do - just time-consuming šŸ˜’

2reactions
Andaristcommented, Dec 11, 2019

Ok, it makes sense - but it still doesnā€™t play OK with defined types because we want to target a styled component with this but this css is typed for a css prop.

Iā€™m not entirely sure about this - but maybe you could add inline annotations (using comments - I think TS supports this) to cast this to any (for starters) and maybe try to type it to an expected type. Donā€™t have a better idea than this right now.

Because of mismatching versions of emotion in that repository with current v11 I had to do extra manual steps each time to get to that props.css problem (because I had to resolve mismatching problems first). I would prefer waiting for a v11 release (hopefully this month) and then trying to work this out when rebass starts using it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Emotion Js and TypeScript problems when passing props to ...
This can be done with the use of interfaces or type aliases. ... export const Hamburguer = styled.button<HamburguerProps>` position:Ā ...
Read more >
TypeScript - Emotion
Emotion includes TypeScript definitions for @emotion/react and @emotion/styled . These definitions infer types for css properties with the object syntax,Ā ...
Read more >
Define function overload types with TypeScript - Kent C. Dodds
Define function overload types with TypeScript ; const logResult = result => console.log(`result: ${result}`) ; asyncAdd(1, 2).then(logResult) //Ā ...
Read more >
@emotion/react | Yarn - Package Manager
... The autoLabel and sourceMap options are on by default in development in ... create-emotion-styled , preact-emotion ... #614 Export "createBroadcast".
Read more >
type 'reactnode' is not assignable to type 'reactelement<any ...
declarations/Breadcrumbs.types'; import defaultClasses from './styles/Breadcrumbs.module.css' export const Breadcrumbs = forwardRef<HTMLLabelElement,Ā ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found