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

[Badge] Fix TS custom variants #24407

Merged
merged 6 commits into from
Jan 14, 2021
Merged

Conversation

mnajdova
Copy link
Member

Closes #24323

@mui-pr-bot
Copy link

mui-pr-bot commented Jan 14, 2021

Details of bundle changes

Generated by 🚫 dangerJS against b6967d0

@oliviertassinari oliviertassinari added component: badge This is the name of the generic UI component, not the React module! typescript labels Jan 14, 2021
},
"default": "'standard'"
},
"variant": { "type": { "name": "string" }, "default": "'standard'" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem intended. We now say Badge expects any string when it only supports 'dot' | 'standard': https://deploy-preview-24407--material-ui.netlify.app/api/badge/

Though it's already not ideal on next: https://next--material-ui.netlify.app/api/badge/

It should just say 'dot' | 'standard', no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: The goal of this PR doesn't need to be 'dot' | 'standard'. Keeping the current one is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a look later on whether we can improve the generation of the docs regarding these kind of props.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a look later on whether we can improve the generation of the docs regarding these kind of props.

When is this later going to be? We already made it worse when introducing string (#22140). Now we're making it worse again. Follow-ups are ok but it's clear to me that they're not working in this instance.

Copy link
Member

@oliviertassinari oliviertassinari Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the expected result in the docs is "string" for the unstyled component. It's meant to not create any constraints when implementing a design spec. For the styled component, it does look like a regression.

Copy link
Member

@eps1lon eps1lon Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already made it worse when introducing string (#22140).

worse better smile

The documentation got worse. Badge#variant does not support arbitrary strings which the change in #22140 implied.

Expected:

  • Badge#variant supports 'dot' | 'standard'
  • UnstyledBadge#variant supports string

Actual:

  • Badge#variant supports string (was wrong before with 'dot' | 'standard' | string)

Only /api/badge is problematic. The types seem correct. They still reject an unsupported variant: a6e460c (#24407)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now, let me take a look on buildApi and what we have there. I think the string may be coming from the unstyled component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the issue in the buildAPI, there are no changes to the /api/badge now. For not including the | string part, let's resolve it separately. I think it will require more work, or we will need to whitelist which props should have a custom documentation logic, so we can extract the string option out of those (variant, color, size and all other props for which we want to support custom defined values)

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're saying this "Closes #24323" but that issue is about module augmentation.

You can now write tests for module augmentation: #24267

@eps1lon eps1lon added the PR: needs test The pull request can't be merged label Jan 14, 2021
@mnajdova
Copy link
Member Author

You can now write tests for module augmentation: #24267

Added test, it's super easy and fast to run. Good job with introducing this @eps1lon

@mnajdova mnajdova requested a review from eps1lon January 14, 2021 11:12
@mnajdova mnajdova removed the PR: needs test The pull request can't be merged label Jan 14, 2021
@mnajdova mnajdova merged commit 69eb1d6 into mui:next Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: badge This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Badge] Typescript Custom Variant does not work
4 participants