File tree 5 files changed +52
-11
lines changed
5 files changed +52
-11
lines changed Original file line number Diff line number Diff line change @@ -170,14 +170,19 @@ export interface Jimp extends JimpConstructors {
170
170
) : this;
171
171
172
172
// Functions
173
- appendConstructorOption < T extends any [ ] > (
173
+ /**
174
+ * I'd like to make `Args` generic and used in `run` and `test` but alas,
175
+ * it's not possible RN:
176
+ * https://github.com/microsoft/TypeScript/issues/26113
177
+ */
178
+ appendConstructorOption < Args extends any [ ] , J extends Jimp = this> (
174
179
name : string ,
175
- test : ( ...args : T [ ] ) => boolean ,
180
+ test : ( ...args : any [ ] ) => boolean ,
176
181
run : (
177
- this : this ,
178
- resolve : ( jimp : this ) => any ,
182
+ this : J ,
183
+ resolve : ( jimp ?: J ) => any ,
179
184
reject : ( reason : Error ) => any ,
180
- ...args : T [ ]
185
+ ...args : any [ ]
181
186
) => any
182
187
) : void ;
183
188
read ( path : string , cb ?: ImageCallback < this> ) : Promise < this> ;
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ export type UnionToIntersection<U> =
13
13
* Left loose as "any" in order to enable the GetPluginValue to work properly
14
14
*/
15
15
export type WellFormedValues < T extends any > =
16
- T [ 'class' ] &
17
- T [ 'constants' ] ;
16
+ ( T extends { class : any } ? T [ 'class' ] : { } ) &
17
+ ( T extends { constants : any } ? T [ 'constants' ] : { } ) ;
18
18
19
19
// Util type for the functions that deal with `@jimp/custom`
20
20
// Must accept any or no props thanks to typing of the `plugins` intersected function
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import resize from '@jimp/plugin-resize';
6
6
import scale from '@jimp/plugin-scale' ;
7
7
import types from '@jimp/types' ;
8
8
import plugins from '@jimp/plugins' ;
9
+ import * as Jimp from 'jimp' ;
9
10
10
11
// configure should return a valid Jimp type with addons
11
12
const CustomJimp = configure ( {
@@ -350,3 +351,20 @@ test('can handle only one plugin', () => {
350
351
// $ExpectError
351
352
Jiimp . func ( ) ;
352
353
} ) ;
354
+
355
+
356
+ test ( 'Can handle appendConstructorOption' , ( ) => {
357
+ const AppendJimp = configure ( { } ) ;
358
+
359
+ AppendJimp . appendConstructorOption (
360
+ 'Name of Option' ,
361
+ args => args . hasSomeCustomThing ,
362
+ function ( resolve , reject , args ) {
363
+ // $ExpectError
364
+ this . bitmap = 3 ;
365
+ // $ExpectError
366
+ AppendJimp . resize ( 2 , 2 ) ;
367
+ resolve ( ) ;
368
+ }
369
+ ) ;
370
+ } ) ;
Original file line number Diff line number Diff line change @@ -341,14 +341,19 @@ interface DepreciatedJimp {
341
341
mask ( src : this, x : number , y : number , cb ?: ImageCallback ) : this;
342
342
343
343
// Functions
344
- appendConstructorOption < T extends any [ ] > (
344
+ /**
345
+ * I'd like to make `Args` generic and used in `run` and `test` but alas,
346
+ * it's not possible RN:
347
+ * https://github.com/microsoft/TypeScript/issues/26113
348
+ */
349
+ appendConstructorOption < Args extends any [ ] > (
345
350
name : string ,
346
- test : ( ...args : T [ ] ) => boolean ,
351
+ test : ( ...args : any [ ] ) => boolean ,
347
352
run : (
348
353
this : this,
349
- resolve : ( jimp : this) => any ,
354
+ resolve : ( jimp ? : this) => any ,
350
355
reject : ( reason : Error ) => any ,
351
- ...args : T [ ]
356
+ ...args : any [ ]
352
357
) => any
353
358
) : void ;
354
359
read ( path : string , cb ?: ImageCallback ) : Promise < this> ;
Original file line number Diff line number Diff line change @@ -86,3 +86,16 @@ test('Can handle callback with constructor', () => {
86
86
cbJimpInst . func ( ) ;
87
87
} ) ;
88
88
} )
89
+
90
+ test ( 'Can handle appendConstructorOption' , ( ) => {
91
+ Jimp . appendConstructorOption (
92
+ 'Name of Option' ,
93
+ args => args . hasSomeCustomThing ,
94
+ function ( resolve , reject , args ) {
95
+ // $ExpectError
96
+ this . bitmap = 3 ;
97
+ Jimp . resize ( 2 , 2 ) ;
98
+ resolve ( ) ;
99
+ }
100
+ ) ;
101
+ } ) ;
You can’t perform that action at this time.
0 commit comments