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

Incorrect TypeScript definition of createStyles() #20864

Closed
2 tasks done
JasonHK opened this issue May 1, 2020 · 4 comments · Fixed by #20866
Closed
2 tasks done

Incorrect TypeScript definition of createStyles() #20864

JasonHK opened this issue May 1, 2020 · 4 comments · Fixed by #20866
Labels
bug 🐛 Something doesn't work typescript

Comments

@JasonHK
Copy link
Contributor

JasonHK commented May 1, 2020

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

According to the documentation, createStyles() should accept either a function or an object, but the TypeScript definition accept an object only.

Expected Behavior 🤔

The TypeScript definition of createStyles() should also accept a function.

Steps to Reproduce 🕹

CodeSandbox reproduction: https://codesandbox.io/s/sparkling-moon-yrppz?file=/src/index.ts

Context 🔦

Your Environment 🌎

Tech Version
Material-UI v4.9.12
React N/A
Browser N/A
TypeScript v3.8.3
etc.
@eps1lon
Copy link
Member

eps1lon commented May 1, 2020

createStyles<IStylesClassKey, IStylesProps>(() => {

We don't accept a function without an argument. The function signature is only useful if you're using the theme:

-createStyles<IStylesClassKey, IStylesProps>(() => {
+createStyles<IStylesClassKey, IStylesProps>(theme => {

@eps1lon eps1lon closed this as completed May 1, 2020
@JasonHK
Copy link
Contributor Author

JasonHK commented May 1, 2020

createStyles<IStylesClassKey, IStylesProps>(() => {

We don't accept a function without an argument. The function signature is only useful if you're using the theme:

-createStyles<IStylesClassKey, IStylesProps>(() => {
+createStyles<IStylesClassKey, IStylesProps>(theme => {

@eps1lon No, TypeScript STILL throws an error after adding the argument. TypeScript doesn't care if the arguments were omitted or not.

Don't you read the description of the issue?

Current Behavior 😯

According to the documentation, createStyles() should accept either a function or an object, but the TypeScript definition accept an object only.

@JasonHK
Copy link
Contributor Author

JasonHK commented May 1, 2020

@eps1lon Is this what you called "working properly"?

2020-05-01_00001

@eps1lon
Copy link
Member

eps1lon commented May 1, 2020

Right, the API docs are wrong. See our TypeScript guide for the correct usage of createStyles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants