egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.29k stars 223 forks source link

[Help] Include other type declaration in the types built by tsup #1229

Closed deslunes closed 1 month ago

deslunes commented 1 month ago

Hello ! I'm writing a Vite Plugin that intercept and manipulate DOM depending on their attribute. Some framework are a bit strict regarding the attributes, so I declare the attributes in a svelte.d.ts file in the src/ directory. Here's an example :

// src/svelte-global.d.ts
import { HTMLAttributes } from 'svelte/elements';

declare module 'svelte/elements' {
    interface HTMLAttributes<T> {
        "sm"?: string;
        "md"?: string;
        "lg"?: string;
        "xl"?: string;
        "2xl"?: string;
    }
}

Svelte "reads" the file wherever it is, as long as it is inside the src directory or one of its children. Over the time, the list of attributes grew, and I want to include it inside the npm package I use to store and share the Vite Plugin.

As of now, I placed the svelte.d.ts file in the root folder of the package. But it's not working. So I modified my tsup.config.ts file in order to tell tsup to use that file. It did work, I got an index.d.ts (for my index.ts file) and a svelte.d.ts (for my svelte.d.ts)

If you want to check it's in this repo: https://github.com/deslunes/vite-plugin-tailwind-attributify

Have a nice day!

Upvote & Fund

Fund with Polar