-
Notifications
You must be signed in to change notification settings - Fork 67
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
Default Export extend Record<string, string> #71
Comments
Thanks for submitting the issue with all the details. I believe the recommendation would defeat the purpose of this package because it would then allow usage of any class (string) on the export interface Styles extends Record<string, string> {
'classname--first': string;
'classname--second': string;
}
export type ClassNames = keyof Styles;
const styles: Styles = {} as Styles;
styles.notARealClass; However, I do see the issue with the code sample you provided. It looks possibly related to this issue: microsoft/TypeScript#15300. I believe if we updated to use a type Styles = {
'classname--first': string;
'classname--second': string;
}
const styles: Styles = {} as Styles;
function foo( bar: Record<string, string> ): string[] {
return Object.keys(bar);
}
foo(styles) // Valid with type Styles = {} but not interface Styles {}` |
I agree completely with your recommendation, it does seem that exporting as a type instead of an interface would resolve my issue. I’ll be able to make a PR for the update and any relevant documentation tomorrow. Thank you for the support. |
…y#71 Before we were unable to do this: ```typescript export interface Styles { 'classname--first': string; 'classname--second': string; } function foo(bar: Record<string, string>){ return Object.keys(bar); } ``` Because an interface does not allow being cast as a wider type. This fixes that by using types instead of interfaces: ```typescript export type Styles = { 'classname--first': string; 'classname--second': string; } ``` BREAKING CHANGE: this can interfere with how others use their default exported classnames
🎉 This issue has been resolved in version 2.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Expected Behavior
I have a function that takes in a default export from a CSS Module but I want there to be a meaningful type for the parameter.
Current Behavior
Export default looks like:
Possible Solution
Export default could look like:
Context
If you have any suggestions on how to have a parameter that is meaningful for my function that would be really helpful but I think extending
Record<string, string>
allows for a lot.Your Environment
The text was updated successfully, but these errors were encountered: