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

Type definitions for the configuration file #3263

Closed
wants to merge 4 commits into from

Conversation

arpadgabor
Copy link

This PR adds a new index.d.ts file that contains type definitions for the configuration object in tailwind.config.js.

With this change every property can be quickly documented so developers can prototype faster instead of looking through the documentation for property names.

  • Usage:

    /** @type {import('tailwindcss').Config} */
    module.exports = {
      theme: {
        screens: { ... },
      }
    }
  • Features:
    Types and interfaces for most (if not all) config properties + variations (e.g. font size with line height)
    Links to documentation for most properties
    Variants with auto-complete in the string array
    Update to stubs to include the JSDoc annotation in new projects

Screenshots

Intellisense for variants array

Intellisense for theme config

Disclaimer: This is my first ever PR, changes should be non-breaking, there may be typos.

@adamwathan
Copy link
Member

Wow thanks for this! I've asked someone on our team who is better with TypeScript to review this and compare it with what we use for types on Tailwind Play, we can probably unify this work somehow 👍🏻 Will hear back from us again in a week or two, sorry for the delay!

@arpadgabor
Copy link
Author

Thanks for the reply! I lack the necessary time at the moment but there are a couple other things I thought could be addressed with this PR:

  • Type definitions for the plugin development API
  • A way for plugin developers to add type definitions to the plugins configs

I'm no expert in typescript (hence why I didn't use declare module because I couldn't get it to work the way I want), but there must be a way of actually extending the base definitions and add new rules based on what plugins we have registered.

I guess one possible way would be with generics and the definitions would be added to theme?.extend and variants:

/**
  @type {import('tailwindcss').Config<
    PluginDefinitions & PluginDefinitions2
  >}
*/

Anyways, this is just something I came up with and did not test at all, maybe the other week if I find some time.

@iamandrewluca
Copy link

iamandrewluca commented May 25, 2021

We are using this package for types at the moment
https://www.npmjs.com/package/@types/tailwindcss
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/tailwindcss

/**
 * @type {import('tailwindcss/tailwind-config').TailwindConfig}
 */
module.exports = {
  // ...
}

@alvis
Copy link

alvis commented Aug 24, 2021

@adamwathan @arpadgabor are there any missing pieces the community can help to get this integrated?

@arpadgabor
Copy link
Author

@alvis at the moment the definitions must be updated to match new utilities from the last few updates. I'd be willing to update the PR if @adamwathan or someone else in the team is interested in merging this.

@RobinMalfait RobinMalfait self-assigned this Feb 23, 2022
@adamwathan
Copy link
Member

Hey! We ended up adding types ourselves in March in this PR: #7891

I completely forgot this one was open otherwise we would have built it on top of yours — so sorry about that 🤦🏻‍♂️ Thank you so much for the PR regardless, hope you continue to contribute in the future.

@adamwathan adamwathan closed this May 4, 2022
@arpadgabor
Copy link
Author

Haha, no worries 🙈, haven't noticed so it's good you mentioned. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants