Skip to content

Add TailwindCSS type definitions#50921

Merged
sheetalkamat merged 12 commits into
DefinitelyTyped:masterfrom
dolanmiu:feat/tailwind2
Mar 8, 2021
Merged

Add TailwindCSS type definitions#50921
sheetalkamat merged 12 commits into
DefinitelyTyped:masterfrom
dolanmiu:feat/tailwind2

Conversation

@dolanmiu

Copy link
Copy Markdown
Contributor

Please fill in this template.

Select one of these and delete the others:

If adding a new definition:

  • The package does not already provide its own types, or cannot have its .d.ts files generated via --declaration
  • If this is for an npm package, match the name. If not, do not conflict with the name of an npm package.
  • Create it with dts-gen --dt, not by basing it on an existing project.
  • Represents shape of module/library correctly
  • tslint.json should contain { "extends": "dtslint/dt.json" }, and no additional rules.
  • tsconfig.json should have noImplicitAny, noImplicitThis, strictNullChecks, and strictFunctionTypes set to true.

Documentation for why:

https://tailwindcss.com/docs/configuration#referencing-in-java-script

See "Referencing in JavaScript"

@typescript-bot

typescript-bot commented Jan 29, 2021

Copy link
Copy Markdown
Contributor

@dolanmiu Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

This PR adds a new definition, so it needs to be reviewed by a DT maintainer before it can be merged.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ❌ Only a DT maintainer can approve changes when there are new packages added

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 50921,
  "author": "dolanmiu",
  "headCommitOid": "3b1d1f5606b2c4285967613d183139d4d083226f",
  "lastPushDate": "2021-03-01T22:40:14.000Z",
  "lastActivityDate": "2021-03-01T22:57:05.000Z",
  "maintainerBlessed": false,
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "popularityLevel": "Well-liked by everyone",
  "pkgInfo": [
    {
      "name": "tailwindcss",
      "kind": "add",
      "files": [
        {
          "path": "types/tailwindcss/colors.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/tailwindcss/defaultTheme.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/tailwindcss/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/tailwindcss/resolveConfig.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/tailwindcss/tailwind-config.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/tailwindcss/tailwindcss-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/tailwindcss/tsconfig.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/tailwindcss/tslint.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [],
      "addedOwners": [
        "dolanmiu"
      ],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    }
  ],
  "reviews": [
    {
      "type": "stale",
      "reviewer": "amcasey",
      "date": "2021-03-01T22:33:15.000Z",
      "abbrOid": "8d91a82"
    },
    {
      "type": "stale",
      "reviewer": "themagickoala",
      "date": "2021-02-18T23:08:45.000Z",
      "abbrOid": "8d91a82"
    },
    {
      "type": "stale",
      "reviewer": "aivenkimmob",
      "date": "2021-02-18T12:19:24.000Z",
      "abbrOid": "8d91a82"
    },
    {
      "type": "stale",
      "reviewer": "peterblazejewicz",
      "date": "2021-02-14T19:50:05.000Z",
      "abbrOid": "8d91a82"
    },
    {
      "type": "stale",
      "reviewer": "sheetalkamat",
      "date": "2021-01-29T22:55:24.000Z",
      "abbrOid": "2049749"
    }
  ],
  "ciResult": "pass"
}

@typescript-bot

Copy link
Copy Markdown
Contributor

🔔 @dolanmiu — you're the only owner, but it would still be good if you find someone to review this PR in the next few days, otherwise a maintainer will look at it. (And if you do find someone, maybe even recruit them to be a second owner to make future changes easier...)

@typescript-bot typescript-bot added New Definition This PR creates a new definition package. Check Config Changes a module config files labels Jan 29, 2021
@danger-public

danger-public commented Jan 29, 2021

Copy link
Copy Markdown

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

tailwindcss (unpkg)

was missing the following properties:

  1. postcss

Generated by 🚫 dangerJS against 8d91a82

@typescript-bot

Copy link
Copy Markdown
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

These typings are for a package that doesn’t yet exist on master, so I don’t have anything to compare against yet! In the future, I’ll be able to compare PRs to tailwindcss with its source on master.

Comparison details 📊
Batch compilation
Type count 3825
Assignability cache size 396
Language service measurements
Samples taken 522
Identifiers in tests 522
getCompletionsAtPosition
    Mean duration (ms) 72.8
    Mean CV 16.2%
    Worst duration (ms) 108.1
    Worst identifier opacity
getQuickInfoAtPosition
    Mean duration (ms) 74.8
    Mean CV 14.2%
    Worst duration (ms) 116.3
    Worst identifier white
System information
Node version v14.15.4
CPU count 2
CPU speed 2.095 GHz
CPU model Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz
CPU Architecture x64
Memory 6.8 GiB
Platform linux
Release 4.15.0-1103-azure

Comment thread types/tailwindcss/index.d.ts Outdated
Comment thread types/tailwindcss/tslint.json Outdated
@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jan 29, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

@dolanmiu One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you!

@dolanmiu

Copy link
Copy Markdown
Contributor Author

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

tailwindcss (unpkg)

was missing the following properties:

  1. The declaration doesn't match the JavaScript module 'tailwindcss'. Reason:
    The JavaScript module can be called or constructed, but the declaration module cannot.

The most common way to resolve this error is to use 'export =' syntax.
To learn more about 'export =' syntax, see https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require.

  1. postcss

Generated by 🚫 dangerJS against 2049749

This is now done

@typescript-bot typescript-bot removed Check Config Changes a module config files Revision needed This PR needs code changes before it can be merged. labels Jan 30, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

@sheetalkamat Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@dolanmiu dolanmiu requested a review from sheetalkamat January 30, 2021 17:11
@dolanmiu

dolanmiu commented Feb 1, 2021

Copy link
Copy Markdown
Contributor Author

@sheetalkamat Could you take a look again please?

@@ -0,0 +1,1186 @@
export type Variant =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a types-only file without a corresponding module in the underlying library. Am I reading that correctly? Is the goal just to prevent consumers from accidentally importing the types? If not, why not just include them in index.d.ts? Possible issues: if a consumer does import this file, will the import still be present at runtime? What happens if the underlying library adds a module with this name (unlikely, since it doesn't seem to follow their naming conventions)?

@dolanmiu dolanmiu Feb 2, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separation of concerns

tailwind-config.d.ts is really big (way over 1000+ lines long), and I did not want to pollute index.d.ts

This library does not export anything of the sort, I had to manually infer this from the documentation.

Similar to how in @types/webpack type definitions, there is a Configuration interface which is no where to be found in webpack itself. This is my goal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not sure I understand. What concerns are you separating? It seems like tailwind-config.d.ts contains the types that are necessary for the declarations in index.d.ts. If you don't want consumers to see the helper types, just don't export them.

I don't follow your point about webpack. There's nothing wrong with adding types not found in the underlying library - that's the point of DefinitelyTyped. My concern is with adding a package not found in the underlying library. Does webpack do that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type definition has zero dependencies, so surely this would not be a problem?

Ok, I could move tailwind-config.d.ts into index.d.ts if that is better? what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by "zero dependencies". If you mean that it doesn't depend on anything, I don't think that's relevant to the file organization. If you mean that nothing depends on it, I think that's only because it hasn't been merged yet - it seems to be quite a popular package.

Yes, as @peterblazejewicz and I have explained, having modules that don't exist in the underlying library makes it more likely that a user will consume it incorrectly and have problems at runtime.

Comment thread types/tailwindcss/index.d.ts
Comment thread types/tailwindcss/resolveConfig.d.ts Outdated
Comment thread types/tailwindcss/resolveConfig.d.ts Outdated
@@ -0,0 +1,5 @@
import { TailwindConfig } from './tailwind-config';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no './tailwind-config.jsin the source, why this cannot belib/util/resolveConfig` import?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be lib/util/resolveConfig because it has to be:

import resolveConfig from 'tailwindcss/resolveConfig'

Is this what you mean?

Source:

https://tailwindcss.com/docs/configuration#referencing-in-java-script

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how to consume the package IMO, not how it's written:
https://github.com/tailwindlabs/tailwindcss/blob/master/resolveConfig.js#L4
https://unpkg.com/tailwindcss@2.0.2/resolveConfig.js
this methods returns outcome of calling the resolvveConfigObjects:

const resolveConfigObjects = require('./lib/util/resolveConfig').default

you can of course skip 'lib/util/resolveConfig' details and just write shared types somewhere. But I'd not create some artificial file for those, just put them into 'index.d.ts' as shared interfaces (types).

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
Comment thread types/tailwindcss/index.d.ts Outdated
Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
Comment thread types/tailwindcss/resolveConfig.d.ts
Comment thread types/tailwindcss/tailwindcss-tests.ts
Comment thread types/tailwindcss/tailwindcss-tests.ts Outdated
@typescript-bot

Copy link
Copy Markdown
Contributor

@peterblazejewicz, @amcasey, @sheetalkamat Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@peterblazejewicz

Copy link
Copy Markdown
Member

Where is default theme?

const defaultTheme = require('tailwindcss/defaultTheme')

it's the object within the theme property of that default config interfacew

@peterblazejewicz

peterblazejewicz commented Feb 2, 2021

Copy link
Copy Markdown
Member

Where is:

const colors = require('tailwindcss/colors')

this one defaines shapes of the colors used by default config theme

@typescript-bot typescript-bot removed the Other Approved This PR was reviewed and signed-off by a community member. label Feb 8, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

@peterblazejewicz, @sheetalkamat Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@dolanmiu

dolanmiu commented Feb 9, 2021

Copy link
Copy Markdown
Contributor Author

@peterblazejewicz My concern is that it will inflate and pollute index.d.ts, and violate separation of concerns

tailwind-config.d.ts is absolutely massive. I am trying to split the code into logical chunks to make future work more maintainable

Look at the following as an example:
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jsforce
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/nodegit

Comment thread types/tailwindcss/tailwind-config.d.ts
@typescript-bot typescript-bot added the Other Approved This PR was reviewed and signed-off by a community member. label Feb 14, 2021

@aivenkimmob aivenkimmob left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to tick the "request changes" but not sure if I misunderstood the big picture here.

Comment thread types/tailwindcss/tailwind-config.d.ts

@amcasey amcasey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please address @aivenkimmob's question? The types shouldn't preclude common usage patterns.

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Maintainer Approved Other Approved This PR was reviewed and signed-off by a community member. Self Merge This PR can now be self-merged by the PR author or an owner labels Feb 18, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

@dolanmiu One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you!

@dolanmiu

Copy link
Copy Markdown
Contributor Author

Can you please address @aivenkimmob's question? The types shouldn't preclude common usage patterns.

done

@dolanmiu dolanmiu requested a review from amcasey February 22, 2021 11:13
@dolanmiu

dolanmiu commented Mar 1, 2021

Copy link
Copy Markdown
Contributor Author

Could someone merge this in? Everything is addressed

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
@typescript-bot typescript-bot removed the Revision needed This PR needs code changes before it can be merged. label Mar 1, 2021
@dolanmiu

dolanmiu commented Mar 1, 2021

Copy link
Copy Markdown
Contributor Author

@amcasey I had to revert the export = resolveConfig; change on resolveConfig.d.ts as it broke the tests

ERROR: 1:8  expect  TypeScript@4.2 compile error: 
Module '"/Users/dmiu/DefinitelyTyped/types/tailwindcss/resolveConfig"' can only be default-imported using the 'esModuleInterop' flag

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Mar 1, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

@dolanmiu The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Mar 1, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

@amcasey, @themagickoala, @aivenkimmob, @peterblazejewicz, @sheetalkamat Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@amcasey

amcasey commented Mar 1, 2021

Copy link
Copy Markdown
Contributor

@amcasey I had to revert the export = resolveConfig; change on resolveConfig.d.ts as it broke the tests

ERROR: 1:8  expect  TypeScript@4.2 compile error: 
Module '"/Users/dmiu/DefinitelyTyped/types/tailwindcss/resolveConfig"' can only be default-imported using the 'esModuleInterop' flag

The error is correct - you need a default export to use a default import. I'm confused because the underlying code does not appear to have a default export. However, as you point out, the docs suggest doing it this way, so I'm fine with reverting the export.

@sheetalkamat sheetalkamat merged commit a189565 into DefinitelyTyped:master Mar 8, 2021
@typescript-bot

Copy link
Copy Markdown
Contributor

I just published @types/tailwindcss@2.0.0 to npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Definition This PR creates a new definition package.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants