Types: Missing overload for default export from @emotion/styled ?
See original GitHub issueThe 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:
- Created 4 years ago
- Reactions:3
- Comments:16 (9 by maintainers)
Top GitHub Comments
While digging into it Iāve even encountered:
š
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 š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.