stitchesjs / stitches

[Not Actively Maintained] CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.
https://stitches.dev
MIT License
7.72k stars 251 forks source link

Typescript error when using `as` with multiple levels of nesting #1105

Open s-h-a-d-o-w opened 1 year ago

s-h-a-d-o-w commented 1 year ago

Bug report

Describe the bug

This fix only works a single level deep. Which might also be why some other people have said that the fix doesn't work for them. But as far as I've seen, nobody has debugged it this way and mentioned multiple levels of nesting, so I thought I should create this new issue.

To Reproduce

Insert const AnotherLevel = styled(Flex, {}) in packages/test/issue-749-react.tsx and use that instead of Flex.

Will throw

No overload matches this call.
  Overload 1 of 3, '(props: Omit<Omit<Omit<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; }, "size" | "css"> & TransformProps<...> & { ...; }, "css" | "variant"> & TransformProps<...> & { ...; }, "as" | "css"> & TransformProps<...> & { ...; }): ReactElement<...> | null', gave the following error.
    Type 'string' is not assignable to type 'undefined'.
...

Expected behavior

as prop should not throw TS errors regardless of levels of nesting.

Screenshots

Screenshot 2022-10-07 152001

System information

Additional context

I have looked at it a bit and TypeScript seems to generate the type recursively with the appropriate props, so I'm not sure what's going on here.

Screenshot 2022-10-07 152455

enk0de commented 1 year ago

+1

s-h-a-d-o-w commented 1 year ago

Please upvote the original post instead of posting +1.