-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[TypeScript] createStyles() does not have smart property hints in the vscode editor #11693
Comments
@franklixuefei if you go the |
@BrendonSled I think it's one way or the other. For now I don't have a solution that's easy enough to cover both cases. The only solution I can think of is to explicitly pass in the keys, like Also, you can put the keys into the type param of It's kind of like a "chicken and egg` problem. See below for a possible solution. type classList =
| 'root'
| 'rule1'
| 'rule2'
;
const styles = ({ palette, spacing, typography }: Theme) => createStyles<StyleRules<classList>>({
root: {...}, // intellisense enabled
rule1: {...},
rule2: {...}
});
...
classes.root; // intellisense enabled
... |
The whole purpose of the const styles: StyleRulesCallback<ClassKey> = ({ palette, spacing, typography }) => ({
...
}); |
@pelotom using the A temporary workaround I've found if you want autocomplete on the CSS properties and inferred class keys is to just add const styles = (theme) => ({
root: {...} as CSSProperties,
rule1: {...} as CSSProperties,
});
...
classes.root; // intellisense enabled |
@BrendonSled I like your workaround. I wish type widening had never been invented. |
@BrendonSled yep, I was just responding to later comments. This seems like maybe an issue worth raising with the TypeScript team? I would think that if the |
I actually did the following const styles = (theme: Theme) => createStyles<StyleRules>(
{
classname: {
somecssprop: "cssvalue"
},
}
);
interface IComponentOwnProps {
classes: {[T in keyof ReturnType<typeof styles>]: T};
} |
@chilbi This should be resolved with #12456 which was released in Edit: We have a fix for now but if this question comes up again we can forward to the typescript issues. |
Expected Behavior
Current Behavior
Context
Your Environment
The text was updated successfully, but these errors were encountered: