Skip to content

Type definitions for the configuration file - #3263

Closed
arpadgabor wants to merge 4 commits into
tailwindlabs:masterfrom
arpadgabor:master
Closed

arpadgabor wants to merge 4 commits into
tailwindlabs:masterfrom
arpadgabor:master

Conversation

@arpadgabor

Copy link
Copy Markdown

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
Copy Markdown
Contributor

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
Copy Markdown
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.

@unrevised6419

unrevised6419 commented May 25, 2021 •

Copy link
Copy Markdown

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

alvis commented Aug 24, 2021

Copy link
Copy Markdown

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

@arpadgabor

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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.

5 participants