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

Need to deprecated enums used for component prop typing #286

Closed
3 of 12 tasks
brionmario opened this issue Oct 11, 2024 · 0 comments · Fixed by #287
Closed
3 of 12 tasks

Need to deprecated enums used for component prop typing #286

brionmario opened this issue Oct 11, 2024 · 0 comments · Fixed by #287
Assignees
Labels
bug Something isn't working package:react Issues/PRs related to the `@oxygen-ui/react` package. typescript Issues related to typings

Comments

@brionmario
Copy link
Member

Describe the issue:
The use of enums for prop typing is causing type mismatches in TypeScript, particularly when passing string values to props that expect enum values. This results in errors when using the component, such as:

No overload matches this call.
Type '"contained"' is not assignable to type 'IconButtonVariants'.

How to reproduce:

  1. Use a component with a prop that expects an enum type (e.g., variant in IconButton).
  2. Pass a string directly (e.g., "contained" or "text") to the prop.

Example:

<IconButton variant="contained" />;

Expected behavior:
The component should allow passing strings directly for props like variant, instead of requiring the enum, to improve flexibility and ease of use.

Proposed Solution:
Move away from using enums for prop typing and switch to string literal unions, which allows using string values directly.

Example:

export type IconButtonVariants = 'contained' | 'text';

This will allow the following usage without causing type errors:

<IconButton variant="contained" />

Additional context:

  • Affected Package:
    • @oxygen-ui/react
  • Library Version: [e.g., 1.10.0, 2.0.0-alpha]
  • OS:
    • Windows
    • Linux
    • Mac
    • Other
  • Browser:
    • Google Chrome
    • Firefox
    • Safari
    • Microsoft Edge
    • Brave
    • Opera
    • Other
@brionmario brionmario added the bug Something isn't working label Oct 11, 2024
@brionmario brionmario self-assigned this Oct 11, 2024
@brionmario brionmario added package:react Issues/PRs related to the `@oxygen-ui/react` package. typescript Issues related to typings labels Oct 11, 2024
@brionmario brionmario changed the title Need to move away from using enums for prop typing Need to deprecated enums used for component prop typing Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:react Issues/PRs related to the `@oxygen-ui/react` package. typescript Issues related to typings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant