`JimpInstance` type can't be used consistently when working with Jimp instances
- Dominant language
- TypeScript
- Stars
- 14.7k
- Forks
- 777
- PR merge metrics
- No merged PRs in 30d
Description
# Expected Behavior
Before v1, it was possible to pass around `Jimp` as a type and throw in the results of `Jimp.read`/`Jimp.create`/`new Jimp`. Example without TS errors:
```ts
import Jimp from "jimp"
const img1 = await Jimp.read("")
const img2 = await Jimp.create("")
const img3 = new Jimp("")
function test(j: Jimp) {}
test(img1) // works
test(img2) // works
test(img3) // works
```
See https://codesandbox.io/p/sandbox/g56q6v?file=%2Findex.mts
# Current Behavior
#1330 already added an improvement via the `JimpInstance` type, but it seems like it doesn't work the same way (interchangeably).
```ts
import { Jimp, JimpInstance } from "jimp";
const inst = new Jimp({ width: 100, height: 100 });
const img = await Jimp.read("…");
function testInstance(j: JimpInstance) {}
function testRead(j: Awaited>) {}
testInstance(img); // error
testRead(img);
testInstance(inst);
testRead(inst); // error
```
See https://codesandbox.io/p/sandbox/jimp-test-249ch8-pk8qdr?file=%2Findex.mts
Workaround for now is to use `Awaited>`
# Failure Information (for bugs)
## Steps to Reproduce
- 0.22.12 behaviour: https://codesandbox.io/p/sandbox/g56q6v?file=%2Findex.mts
- 1.6.0 behaviour: https://codesandbox.io/p/sandbox/jimp-test-249ch8-pk8qdr?file=%2Findex.mts
---
Ref. https://github.com/jimp-dev/jimp/issues/1328#issuecomment-2337770442
Contributor guide
Assessment
This issue has not been assessed yet.