tailwindlabs / prettier-plugin-tailwindcss

A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order.
MIT License
5.66k stars 135 forks source link

0.6.3 didn't expose PluginOptions interface #291

Closed exneval closed 5 months ago

exneval commented 5 months ago

What version of prettier-plugin-tailwindcss are you using?

v0.6.3

What version of Tailwind CSS are you using?

v3.4.4

What version of Node.js are you using?

v20.13.1

What package manager are you using?

pnpm

What operating system are you using?

Ubuntu

Reproduction URL

-

Describe your issue

Found typing issue with 0.6.3

/** @typedef {import("prettier-plugin-tailwindcss").PluginOptions} TailwindConfig */

the line above not working anymore

0.6.2 index.d.ts

import { Parser, Printer, SupportOption } from 'prettier'

export interface PluginOptions {
  /**
   * Path to the Tailwind config file.
   */
  tailwindConfig?: string

  /**
   * Path to the Tailwind entry point (v4+)
   */
  tailwindEntryPoint?: string

  /**
   * List of custom function and tag names that contain classes.
   */
  tailwindFunctions?: string[]

  /**
   * List of custom attributes that contain classes.
   */
  tailwindAttributes?: string[]
}

declare module 'prettier' {
  interface RequiredOptions extends PluginOptions {}
  interface ParserOptions extends PluginOptions {}
}

export const options: Record<keyof PluginOptions, SupportOption>
export const parsers: Record<string, Parser>
export const printers: Record<string, Printer>

0.6.3 index.d.ts

import { SupportOption, Printer, Parser } from 'prettier';

declare const options: Record<string, SupportOption>;

declare const printers: Record<string, Printer>;
declare const parsers: Record<string, Parser>;
interface PluginOptions {
    /**
     * Path to the Tailwind config file.
     */
    tailwindConfig?: string;
    /**
     * Path to the Tailwind entry point (v4+)
     */
    tailwindEntryPoint?: string;
    /**
     * List of custom function and tag names that contain classes.
     */
    tailwindFunctions?: string[];
    /**
     * List of custom attributes that contain classes.
     */
    tailwindAttributes?: string[];
}
declare module 'prettier' {
    interface RequiredOptions extends PluginOptions {
    }
    interface ParserOptions extends PluginOptions {
    }
}

export { options, parsers, printers };
thecrypticace commented 5 months ago

Is there a reason you're typing as PluginOptions from our plugin rather than Options from prettier?

e.g. /** @type {import('prettier').Options} */

exneval commented 5 months ago

Is there a reason you're typing as PluginOptions from our plugin rather than Options from prettier?

e.g. /** @type {import('prettier').Options} */

It happened to be in a config from this project

can you give a recommendation for how to use it start from 0.6.3?

biohackerellie commented 5 months ago

@exneval

if you're using an isolated prettier module like in t3's monorepo example, you can get around this by adding a types.d.ts to the prettier package and set it yourself until it gets resolved, like this

//prettier/types.d.ts
declare module "prettier-plugin-tailwindcss" {

  export interface PluginOptions {
    /**
     * Path to the Tailwind config file.
     */
    tailwindConfig?: string;
    /**
     * Path to the Tailwind entry point (v4+)
     */
    tailwindEntryPoint?: string;
    /**
     * List of custom function and tag names that contain classes.
     */
    tailwindFunctions?: string[];
    /**
     * List of custom attributes that contain classes.
     */
    tailwindAttributes?: string[];
  }
}
thecrypticace commented 5 months ago

@exneval @biohackerellie If you have control over the config you should just remove the import and the typedef. The definitions will still show up and click through will still work. It's the entire reason we have the declare module 'prettier' { … } code in the types:

Screenshot 2024-06-12 at 14 36 11 Screenshot 2024-06-12 at 14 36 23

I'm going to merge in a fix for this and push a patch release out because it's an unintentional breaking change — but as far as I know there should never be a reason for a project to need to import or use that type.

thecrypticace commented 5 months ago

Fix released in v0.6.4

thecrypticace commented 5 months ago

Aside: I just created a project with that template and it indeed doesn't work by default. Something must be going on with the typescript config there because it's supposed to work.

Adding a reference comment in the file fixes this tho:

/// <reference types="prettier-plugin-tailwindcss" />
biohackerellie commented 5 months ago

Tagging @juliusmarminge here since this should be updated in t3-turbo as well

juliusmarminge commented 5 months ago

Tagging @juliusmarminge here since this should be updated in t3-turbo as well

File a PR :)