mkdist icon indicating copy to clipboard operation
mkdist copied to clipboard

Expected declaration extensions for vue components

Open cjpearson opened this issue 10 months ago • 1 comments

Describe the feature

Follow-up discussion from https://github.com/unjs/mkdist/pull/268#discussion_r1885496778

Currently the declaration files for Vue components are named component.vue.d.ts. According the TypeScript docs, it seems component.vue.d.ts will work for CommonJS resolution, but for ESM they should follow the pattern component.d.vue.ts and enable allowArbitraryExtensions.

Note that historically, a similar effect has often been achievable by adding a declaration file named app.css.d.ts instead of app.d.css.ts - however, this just worked through Node’s require resolution rules for CommonJS. Strictly speaking, the former is interpreted as a declaration file for a JavaScript file named app.css.js. Because relative files imports need to include extensions in Node’s ESM support, TypeScript would error on our example in an ESM file under --moduleResolution node16 or nodenext.

How should mkdist handle this? It seems that using component.d.vue.ts might be more correct, but would require consumers to enable allowArbitraryExtensions. It would also depend on if the Vue component is compiled to a Vue or JS file since the declaration extension should match the output extension.

Input Output Code Output Declaration
component.vue component.vue.js component.d.ts
component.vue component.vue.mjs component.d.mts
component.vue component.vue.cjs component.d.cts
component.vue component.vue component.d.vue.ts

Additional information

  • [X] Would you be willing to help implement this feature?

cjpearson avatar Dec 15 '24 16:12 cjpearson