jakejarvis / imagemin-overwrite

Minify images seamlessly and in-place
https://www.npmjs.com/package/imagemin-overwrite
MIT License
4 stars 1 forks source link

Issue with TypeScript #47

Open hyoretsu opened 4 years ago

hyoretsu commented 4 years ago

It throws up a type definition error when importing module. Tried tweaking imagemin's @types/imagemin, but it didn't work.

// Type definitions for imagemin 7.0
// Project: https://github.com/imagemin/imagemin#readme
// Definitions by: Romain Faust <https://github.com/romain-faust>
//                 Jeff Chan <https://github.com/hkjeffchan>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />

declare function imagemin(input: ReadonlyArray<string>, options?: imagemin.Options): Promise<imagemin.Result[]>;

declare module 'imagemin-overwrite' {
 type Plugin = (input: Buffer) => Promise<Buffer>;

 interface Options {
  destination?: string;
  plugins: ReadonlyArray<Plugin>;
  glob?: boolean;
 }

 interface Result {
  data: Buffer;
  sourcePath: string;
  destinationPath: string;
 }

 interface BufferOptions {
  plugins: ReadonlyArray<Plugin>;
 }

 function buffer(buffer: Buffer, options?: BufferOptions): Promise<Buffer>;
}

export = imagemin;

Also ty for this fork, dunno why this isn't even an option on imagemin.

hyoretsu commented 4 years ago

If export = imagemin; is inside of declare module 'imagemin-overwrite' the file now works and types error goes away, (same for simply writing declare module 'imagemin-overwrite';) but there's no auto import. If you leave it outside it doesn't work anymore but you're able to auto import, although from custom @types folder.