jimp-compact icon indicating copy to clipboard operation
jimp-compact copied to clipboard

How to get TS support for this package?

Open albertodiazdorado opened this issue 4 years ago • 5 comments

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?

albertodiazdorado avatar Sep 01 '21 11:09 albertodiazdorado

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

pi0 avatar Sep 01 '21 18:09 pi0

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 :)

albertodiazdorado avatar Sep 02 '21 11:09 albertodiazdorado

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;
}

SimenB avatar Sep 20 '21 13:09 SimenB

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

pi0 avatar Sep 20 '21 17:09 pi0

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)

SimenB avatar Sep 21 '21 13:09 SimenB