unjs / jimp-compact

✏️ Lightweight version of Jimp -- An image processing library written entirely in JavaScript for Node.js
111 stars 5 forks source link

How to get TS support for this package? #39

Open albertodiazdorado opened 3 years ago

albertodiazdorado commented 3 years ago

I want to use jimp-compact instead of jimp, but I also want to use the type support provided by @types/jimp. How do I do it?

pi0 commented 3 years ago

Hi @albertodiazdorado. I didn't try but can you please try adding "jimp": "npm:jimp-compat" to dependencies of package.json as a workaround? It should work by replacing package but importing jimp

albertodiazdorado commented 3 years ago

Thanks for the answer @pi0 ! Sadly, I have realised that @types/jimp has jimp as a dependency... hence, we are considering dropping the types completely, or switching to jimp.

I will let you know if "jimp": "npm:jimp-compat" works, though :)

SimenB commented 3 years ago

jimp ships with types, so that won't work.

Integrating something like https://api-extractor.com/ might be a good idea 🙂

Workaround for us is jimp as a dev dependency, then in a types.d.ts

declare module 'jimp-compact' {
  import jimp = require('jimp');

  export = jimp;
}
pi0 commented 3 years ago

Version 0.16.1-1 contains a quick fix so as long as you install jimp in devDependencies, types can work for jimp-compact import without the need of alias or ts shim.

image

Integrating something like https://api-extractor.com/ might be a good idea 🙂

Thanks for suggestion. I tried few rollup plugins as well as api-extractor but seems little bit tricky. If interested you can track progress at https://github.com/unjs/jimp-compact/pull/42

SimenB commented 3 years ago

Cool, can remove our own declare module 'jimp-compact' with that 👍

I'm hoping you can get api-extractor (or something similar) to work so we can also drop the dev dep 😀 (for my use case this is perfectly fine though, as the types are only used for dev, and it's more the require time than yarn install time we wanna improve by using this module)