#1337·jimp

`JimpInstance` type can't be used consistently when working with Jimp instances

Author: vntwCreated Sep 9, 2024Updated Apr 21, 2026

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:

typescript
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).

typescript
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<ReturnType<typeof Jimp.read>>) {}

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<ReturnType<typeof Jimp.read>>

Failure Information (for bugs)

Steps to Reproduce


Ref. https://github.com/jimp-dev/jimp/issues/1328#issuecomment-2337770442