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

Typescript support #16

Open
gauravkumar37 opened this issue Sep 28, 2020 · 1 comment
Open

Typescript support #16

gauravkumar37 opened this issue Sep 28, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@gauravkumar37
Copy link

gauravkumar37 commented Sep 28, 2020

Thank you for the wonderful library, I have tried dozens of CSS-in-JS library but this one ticks almost all my requirements while using Next.js
When using this in a typescript project, I noticed that it doesn't have any typescript definition files.
So, for now I have used it like this:

  1. Create a new file react-css-modules.macro.d.ts. This defines the macro function.
declare module 'react-css-modules.macro' {
  export const macro: (styles: any) => void;
}
  1. Create a new file react.d.ts. This adds the styleName prop to all react attributes.
import 'react';

declare module 'react' {
  interface Attributes {
    styleName?: string | boolean;
  }
}
  1. Include these in tsconfig.json
  "include": [
    "next-env.d.ts",
    "react.d.ts",
    "react-css-modules.macro",
    "**/*.ts",
    "**/*.tsx"
  ],

This setup is working fine in Next.js Typescript project.


Also, I noticed that the README states the default value of warning is false but it is true in the code:


Lastly, I was wondering if this library could do all the work in compile-time and thus avoid runtime overhead, however small that may be. Is this possible?
Thanks.

@bohdanbirdie
Copy link
Owner

Hello, @gauravkumar37
Thanks for the feedback

I probably somehow forgot to add the details about TS support
Would you mind making a Pull Request updating the docs?
I'm quite busy at the time to do that my self

@bohdanbirdie bohdanbirdie added the enhancement New feature or request label Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants