Skip to content

Commit

Permalink
Added callback to jimp constructor typings (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn authored and hipstersmoothie committed Nov 26, 2019
1 parent 0591e73 commit d406d79
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
33 changes: 22 additions & 11 deletions packages/core/types/jimp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,18 @@ export interface Jimp extends JimpConstructors {
y: number,
cb?: GenericCallback<number, any, this>
): number;
setPixelColor(hex: number, x: number, y: number, cb?: ImageCallback<this>): this;
setPixelColour(hex: number, x: number, y: number, cb?: ImageCallback<this>): this;
setPixelColor(
hex: number,
x: number,
y: number,
cb?: ImageCallback<this>
): this;
setPixelColour(
hex: number,
x: number,
y: number,
cb?: ImageCallback<this>
): this;
clone(cb?: ImageCallback<this>): this;
cloneQuiet(cb?: ImageCallback<this>): this;
background(hex: number, cb?: ImageCallback<this>): this;
Expand Down Expand Up @@ -170,10 +180,15 @@ export interface Jimp extends JimpConstructors {
...args: T[]
) => any
): void;
read(path: string): Promise<this>;
read(image: Jimp): Promise<this>;
read(data: Buffer): Promise<this>;
read(w: number, h: number, background?: number | string): Promise<this>;
read(path: string, cb?: ImageCallback<this>): Promise<this>;
read(image: Jimp, cb?: ImageCallback<this>): Promise<this>;
read(data: Buffer, cb?: ImageCallback<this>): Promise<this>;
read(
w: number,
h: number,
background?: number | string,
cb?: ImageCallback<this>
): Promise<this>;
create(path: string): Promise<this>;
create(image: Jimp): Promise<this>;
create(data: Buffer): Promise<this>;
Expand All @@ -188,11 +203,7 @@ export interface Jimp extends JimpConstructors {
intToRGBA(i: number, cb?: GenericCallback<RGBA>): RGBA;
cssColorToHex(cssColor: string): number;
limit255(n: number): number;
diff(
img1: Jimp,
img2: Jimp,
threshold?: number
): DiffReturn<this>;
diff(img1: Jimp, img2: Jimp, threshold?: number): DiffReturn<this>;
distance(img1: Jimp, img2: Jimp): number;
compareHashes(hash1: string, hash2: string): number;
colorDiff(rgba1: RGB, rgba2: RGB): number;
Expand Down
14 changes: 9 additions & 5 deletions packages/jimp/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,15 @@ interface DepreciatedJimp {
...args: T[]
) => any
): void;
read(path: string): Promise<this>;
read(image: this): Promise<this>;
read(data: Buffer): Promise<this>;
read(w: number, h: number, background?: number | string): Promise<this>;
create(path: string): Promise<this>;
read(path: string, cb?: ImageCallback): Promise<this>;
read(image: this, cb?: ImageCallback): Promise<this>;
read(data: Buffer, cb?: ImageCallback): Promise<this>;
read(
w: number,
h: number,
background?: number | string,
cb?: ImageCallback
): Promise<this>; create(path: string): Promise<this>;
create(image: this): Promise<this>;
create(data: Buffer): Promise<this>;
create(w: number, h: number, background?: number | string): Promise<this>;
Expand Down
18 changes: 18 additions & 0 deletions packages/jimp/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,21 @@ test('can clone properly', async () => {
})
})
});

test('Can handle callback with constructor', () => {
const myBmpBuffer: Buffer = {} as any;

Jimp.read(myBmpBuffer, (err, cbJimpInst) => {
cbJimpInst.read('Test');
cbJimpInst.displace(jimpInst, 2);
cbJimpInst.resize(40, 40);
// $ExpectType 0
cbJimpInst.PNG_FILTER_NONE;

// $ExpectError
cbJimpInst.test;

// $ExpectError
cbJimpInst.func();
});
})
18 changes: 18 additions & 0 deletions packages/jimp/types/ts3.1/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,21 @@ test('can clone properly', async () => {
})
})
});

test('Can handle callback with constructor', () => {
const myBmpBuffer: Buffer = {} as any;

Jimp.read(myBmpBuffer, (err, cbJimpInst) => {
cbJimpInst.read('Test');
cbJimpInst.displace(jimpInst, 2);
cbJimpInst.resize(40, 40);
// $ExpectType 0
cbJimpInst.PNG_FILTER_NONE;

// $ExpectError
cbJimpInst.test;

// $ExpectError
cbJimpInst.func();
});
});

0 comments on commit d406d79

Please sign in to comment.