cpsoinos / nuxt-svgo

SVGO loader for Nuxt
MIT License
139 stars 10 forks source link

Add missing `types` export for esm and re-export type `SvgLoaderOptions` #267

Closed dsvgl closed 4 months ago

dsvgl commented 4 months ago

I wanted to use exported SvgLoaderOptions type in my custom module like this.

import type { SvgLoaderOptions } from 'nuxt-svgo';

But TS complains:

There are types at /Users/xxx/code/my-repo/packages/nuxt-modules/node_modules/nuxt-svgo/dist/module.d.ts', but this result could not be resolved when respecting package.json "exports". The nuxt-svgo' library may need to update its package.json or typings.

There are types defined in nuxt-svgo package.json for cjs with this line: "types": "./dist/module.d.ts". The types property under the exports key is missing:

"exports": {
  ".": {
    "import": "./dist/module.mjs",
    "require": "./dist/module.cjs",
    "types": "./dist/module.d.ts"  // <------- add this
  }
},

I tested that this solves it by modifying package.json inside node_modules.

With this, I can import the type ModuleOptions from nuxt-svgo. But not type SvgLoaderOptions. Could you also re-export SvgLoaderOptions within your module.ts like so (not totally sure if this would work)?

import { SvgLoaderOptions, svgLoader } from './loaders/vite'
export { SvgLoaderOptions } from './loaders/vite' // <------- add this

But I can also work with type ModuleOptions by index-accessing it with autoImportPath.

let nuxtSvgoModuleAutoImportPath: ModuleOptions['autoImportPath'] = false;
jd1378 commented 4 months ago

Hi sure, will do in a moment

jd1378 commented 4 months ago

released in v4.0.1

dsvgl commented 4 months ago

Thank you! 💖