jhuckaby / webp-wasm

Encode and decode WEBP images using libwebp compiled to WebAssembly.
MIT License
18 stars 0 forks source link

Missing type definitions files (*.d.ts) #2

Open Eptagone opened 9 months ago

Eptagone commented 9 months ago

Hi. I'm looking for a WebP library to use it in my TypeScript project. I just discovered this one but the package doesn't have type definitions files so it can't be used in TypeScript projects yet. It'd be so nice adding type definitions to the project.

The following errors appear because that.

Could not find a declaration file for module 'webp-wasm'. '/home/eptadot/source/test-webp/node_modules/webp-wasm/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/webp-wasm` if it exists or add a new declaration (*.d.ts) file containing `declare module 'webp-wasm';`
a0s commented 3 months ago

Found this issue too.. Any solution?

jhuckaby commented 3 months ago

Hey there, author here. I'm so sorry, but I know NOTHING about TypeScript. I am a native JavaScript developer. However, I asked ChatGPT 4 to help:

https://chatgpt.com/share/dae297ec-445c-492b-96ad-5f32f2ae2e95

The file it produced seems okay to me, so I'm going to just go ahead and check it in, and then will publish a new revision of the library. I apologize, but I have no idea how to even verify it works. As I said, I'm not a TypeScript dev, so this is all foreign to me.

I'll leave this issue open.

jhuckaby commented 3 months ago

Released v1.0.5 with ChatGPT's webp-wasm.d.ts file included:

https://github.com/jhuckaby/webp-wasm/blob/main/webp-wasm.d.ts

a0s commented 3 months ago

Thank you! Funny, i'am using TypeScript and know nothing about pure js except 9+"1"==="91" meme. Also i checked almost the same request to claude.ai, its answered with additional callback related things:


declare module 'webp-wasm' {
  export interface ImageData {
    data: Uint8ClampedArray;
    width: number;
    height: number;
  }

  export interface EncodeOptions {
    // skipped..
  }

  export function load(): Promise<void>;
  export function decode(buffer: Buffer | ArrayBuffer): Promise<ImageData>;
  export function encode(imgData: ImageData, options?: EncodeOptions): Promise<Buffer>;

  // For users who prefer callback-style:
  export function load(callback: (err: Error | null) => void): void;
  export function decode(buffer: Buffer | ArrayBuffer, callback: (err: Error | null, imgData: ImageData) => void): void;
  export function encode(imgData: ImageData, options: EncodeOptions, callback: (err: Error | null, buffer: Buffer) => void): void;
}
a0s commented 3 months ago

@jhuckaby Checked 1.0.5, looks like you forgot "types": "webp-wasm.d.ts" in package.json, isn't ?

jhuckaby commented 3 months ago

Thank you, @a0s. I will add these changes. I had no idea that I needed something in package.json for defining types.

jhuckaby commented 3 months ago

Released v1.0.6 with your changes, @a0s. Cheers!