Add TypeScript definitions
glen-84 opened this issue · 5 comments
I'm using imagemin-webpack
in my webpack configuration, and it would be nice to have type definitions for this loader.
This is fairly easy to add:
- Run
npm install --save-dev typescript
. - Create a
tsconfig.json
file like:{ "compilerOptions": { "target": "ES5", "outDir": "types", "newLine": "LF", "allowJs": true, "declaration": true, "emitDeclarationOnly": true }, "include": [ "index.js", "src/**/*" ], "compileOnSave": false }
- Add
"types": "types/index.d.ts"
topackage.json
. - Run
npx tsc
to generate the declaration files.
(optional: Add an npm script and add some JSDoc comments)
Yep, good idea, it is on roadmap for all loaders/plugins, feel free to send a PR
Sorry to ask on this closed issue but how can we access the different types?
From types/cjs.d.ts
, it seems only the default ImageMinimizerPlugin
is re-exported.
I would like to use the PluginOptions
type for instance (to reference it in a shared configuration)
So far the workaround I found is:
import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
import type { PluginOptions as ImageMinimizerPluginOptions } from 'image-minimizer-webpack-plugin/types/index';
But is there a way with a single import?
PluginOptions is any, but yes we should improve this, we prepare new major release, I will try to improve this
Hi @alexander-akait, thanks for the quick answer :)
I was thinking about this interface: https://github.com/webpack-contrib/image-minimizer-webpack-plugin/blob/master/types/index.d.ts#L6
It is pretty good I think, but I'd rather be able to import it from the package:
import ImageMinimizerPlugin, { PluginOptions as ImageMinimizerPluginOptions } from 'image-minimizer-webpack-plugin';
You can get them from ImageMinimizerPlugin
, i.e. ImageMinimizerPlugin['options']
, types some wrong right now