Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Typescript support for components using forwardRef #51

Closed
jrson83 opened this issue Sep 6, 2023 · 1 comment · Fixed by #74
Closed

[bug] Typescript support for components using forwardRef #51

jrson83 opened this issue Sep 6, 2023 · 1 comment · Fixed by #74
Labels
bug Something isn't working
Milestone

Comments

@jrson83
Copy link
Collaborator

jrson83 commented Sep 6, 2023

Describe the bug

It might be just not integrated yet. When using forwardRef on a component and assigning args, IDE throws a type error. This happens when exporting a default function, but also when exporting default const Button. Or maybe my typings are wrong.

Screenshot 2023-09-06 101234

Reproduction

Example simplified component:

// button.tsx
import { type ComponentPropsWithRef, forwardRef } from 'react'

export type ButtonProps = Omit<ComponentPropsWithRef<'button'>, 'onClick'> & {
  /** Button color from theme */
  color?: string
  onClick?: (data: unknown) => void
}

export default forwardRef<HTMLButtonElement, ButtonProps>(
  ({ children, className = 'btn', color, type = 'button', ...rest }, ref) => {
    return (
      <button type={type} ref={ref} {...rest}>
        {children}
      </button>
    )
  }
)

// button.stories.tsx
import { Story } from '@storylite/storylite'
import Button from './button'

type StoryType = Story<typeof Button>

export default {
  title: 'Button',
  component: Button,
  args: {
    color: undefined, // error
    children: 'Default',
  },
  decorators: [
    (Story, context) => {
      return (
        <div className="example-wrapper">
          <Story {...context?.args} />
        </div>
      )
    },
  ],
} satisfies StoryType

export const Main: StoryType = {
  name: 'Default',
}

Environment

  • OS with version: Windows 11
  • Browser with version Firefox 117.0
  • JS Runtime with version: NodeJS v20.2.0
@itsjavi itsjavi added the bug Something isn't working label Sep 6, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in StoryLite Board Sep 7, 2023
@itsjavi itsjavi moved this from 🆕 New to 📋 Backlog in StoryLite Board Sep 7, 2023
@itsjavi itsjavi added this to the v1.0.0 milestone Sep 12, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in StoryLite Board Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants