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

[styles] Support string templates in TypeScript #16940

Closed
wants to merge 1 commit into from

Conversation

rogerclotet
Copy link
Contributor

@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation typescript labels Aug 8, 2019
@mui-pr-bot
Copy link

mui-pr-bot commented Aug 8, 2019

No bundle size changes comparing 0168a6d...079f8f7

Generated by 🚫 dangerJS against 079f8f7

@oliviertassinari oliviertassinari changed the title [styles] Support string templates in Typescript [styles] Support string templates in TypeScript Aug 8, 2019
Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

makeStyles doesn't support string templates without a plugin, so updating the types to always allow strings isn't exactly correct.
cc @eps1lon

Shouldn't update the hook, should update the Styles type instead.
https://github.com/mui-org/material-ui/blob/5dc2402c9df6f148756129bdabdb1e2fd8363713/packages/material-ui-styles/src/withStyles/withStyles.d.ts#L46-L47

@@ -41,6 +41,6 @@ export default function makeStyles<
Props extends {} = {},
ClassKey extends string = string
>(
styles: Styles<Theme, Props, ClassKey>,
styles: Styles<Theme, Props, ClassKey> | Record<ClassKey, string>,
Copy link
Member

Choose a reason for hiding this comment

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

@rogerclotet
Copy link
Contributor Author

rogerclotet commented Aug 9, 2019

makeStyles doesn't support string templates without a plugin, so updating the types to always allow strings isn't exactly correct.
cc @eps1lon

You're right, maybe this change is not correct. What should I do then, is there a way of making it available only in those cases? Should we even bother with that or leaving it as a javascript-only feature instead?

Shouldn't update the hook, should update the Styles type instead.

https://github.com/mui-org/material-ui/blob/5dc2402c9df6f148756129bdabdb1e2fd8363713/packages/material-ui-styles/src/withStyles/withStyles.d.ts#L46-L47

Updating the Styles type didn't work, it's used in other places and modifying it resulted in invalid return types. I don't have the code right now, but I can reproduce it if you're interested.

Thank you for your feedback!

@eps1lon
Copy link
Member

eps1lon commented Aug 9, 2019

I think we should only document how to augment the types with the plugin. Those types shouldn't be added to the library definitions if they require a runtime plugin.

Hopefully this "just" works with type augmentation. Otherwise we might have to adjust the types. @merceyz made some changes to the types recently to improve type augmentation so he probably knows better how to make this work.

@merceyz
Copy link
Member

merceyz commented Aug 10, 2019

It's currently not possible to augment a type, you can only add things to an interface using augmentation.

You could however do something like this microsoft/TypeScript#28078 (comment)

@oliviertassinari
Copy link
Member

How do you guys want to move forward? I tends to think that almost nobody use the template approach. Until it has support for nested rules, it's not very useful. Also, moving to styled-components will make the concern obsolete. So maybe, we should ignore the problem?

@rogerclotet
Copy link
Contributor Author

I agree, I don't think most people will use string templates, I just wanted to cover this in Typescript, but you can close the PR if you think it's not worth the hassle.

Please update the issue as well marking this as not needed.

@oliviertassinari
Copy link
Member

I have updated the related issue.

@rogerclotet rogerclotet deleted the styles/makeStyles branch August 18, 2019 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants