question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type pattern for partial classes override

See original GitHub issue

When using makeStyles with Typescript, it requires all styles as follows: image

Argument of type '{ root: { minWidth: number; }; }' is not assignable to parameter of type 'Styles<Theme, {}, ButtonClassKey>'.
  Type '{ root: { minWidth: number; }; }' is missing the following properties from type 'Record<ButtonClassKey, CSSProperties | ((props: {}) => CSSProperties)>': label, text, textPrimary, textSecondary, and 12 more.ts(2345)

In my understanding, only the styles I want can be provided.

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

No type error occurs.

Current Behavior 😯

Type error occurs.

Steps to Reproduce 🕹

Context 🔦

Your Environment 🌎

Tech Version
Material-UI 4.0.0-rc.0
React 16.8.6
TypeScript 3.4.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
stephenhcommented, Oct 15, 2019

It really comes down to someone contributing this change and then seeing how our test suite reacts to it.

Cool! I’ll see if my itch persists and try it out if I get a chance.

1reaction
stephenhcommented, Oct 15, 2019

@eps1lon so, I’m not really following; @takakobem and I want to do the same thing, of purposefully restricting our styles def to known-good class keys, i.e. your comment here:

As soon as you would declare a class key that isn’t in the styles of the Button you would get an error anyway when you end up with <Button classes={useStyles()} />

Ah, okay, I see, you’re right; FWIW I’m using createStyles via the withStyles HOC, which doesn’t catch that:

// useStyles has an invalid class key in it
export const MyButton = withStyles(useStyles)(Button);

Granted, it looks like withStyles has some anys in it and HOC’s in general are a pita to get types right, hence why I wanted/expected to do the enforcement on the createStyles side…

I guess also, why not change createStyles to take the a Partial, or is the idea that that would break some of the type inference that is currently happening for the classes={useStyles()} usage?

If it would, then it makes sense to keep as-is since a majority of use cases do what it inferred. I didn’t realize the classes={useStyles()} would catch this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type pattern for partial classes override · Issue #15777 - GitHub
When using makeStyles with Typescript, it requires all styles as follows: Argument of type '{ root: { minWidth: number; } ...
Read more >
Partial Classes and Methods - C# Programming Guide
Partial classes and methods in C# split the definition of a class, a struct, an interface, or a method over two or more...
Read more >
How to override a partial class property - Stack Overflow
The partial keyword on a class just means that it can be declared multiple times in the same assembly.
Read more >
C# Partial Classes and Methods - TutorialsTeacher
Partial classes or structs can contain a method that split into two separate .cs files of the partial class or struct. One of...
Read more >
Partial Class and Partial Methods in C# - Dot Net Tutorials
In this article, I am going to discuss Partial Classes and ... Why we Should Override ToString Method in C# ... Only One...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found