Skip to content

Commit e4e7384

Browse files
committed
Move lib/types.d.ts generation to separate script.
Fixes Promise<T>, ensures module prefix is declared.
1 parent effa77a commit e4e7384

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

lib/types.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
declare module "sharp" {
2+
13
/**
24
* @class Sharp
35
*
@@ -202,7 +204,7 @@ declare function clone(): Sharp;
202204
* @param {Function} [callback] - called with the arguments `(err, metadata)`
203205
* @returns {Promise<Object>|Sharp}
204206
*/
205-
declare function metadata(callback?: (() => any)): (Promise.<Object>|Sharp);
207+
declare function metadata(callback?: (() => any)): (Promise<Object>|Sharp);
206208

207209
/**
208210
* Do not process input images where the number of pixels (width * height) exceeds this limit.
@@ -792,7 +794,7 @@ declare function bandbool(boolOp: String): Sharp;
792794
* @returns {Promise<Object>} - when no callback is provided
793795
* @throws {Error} Invalid parameters
794796
*/
795-
declare function toFile(fileOut: String, callback?: (() => any)): Promise.<Object>;
797+
declare function toFile(fileOut: String, callback?: (() => any)): Promise<Object>;
796798

797799
/**
798800
* Write output to a Buffer.
@@ -806,7 +808,7 @@ declare function toFile(fileOut: String, callback?: (() => any)): Promise.<Objec
806808
* @param {Function} [callback]
807809
* @returns {Promise<Buffer>} - when no callback is provided
808810
*/
809-
declare function toBuffer(callback?: (() => any)): Promise.<Buffer>;
811+
declare function toBuffer(callback?: (() => any)): Promise<Buffer>;
810812

811813
/**
812814
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
@@ -1017,3 +1019,5 @@ declare function counters(): Object;
10171019
*/
10181020
declare function simd(simd?: Boolean): Boolean;
10191021

1022+
}
1023+

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"test-leak": "./test/leak/leak.sh",
3838
"test-packaging": "./packaging/test-linux-x64.sh",
3939
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done",
40-
"types": "cd lib && jsdoc -d . -t ../node_modules/tsd-jsdoc constructor.js input.js resize.js composite.js operation.js colour.js channel.js output.js utility.js"
40+
"types": "./packaging/types.sh"
4141
},
4242
"main": "lib/index.js",
4343
"types": "lib/types.d.ts",
@@ -81,7 +81,7 @@
8181
"nyc": "^9.0.1",
8282
"rimraf": "^2.5.4",
8383
"semistandard": "^9.1.0",
84-
"tsd-jsdoc": "^1.0.1",
84+
"tsd-jsdoc": "lovell/tsd-jsdoc#add-support-for-promises",
8585
"unzip": "^0.1.11"
8686
},
8787
"license": "Apache-2.0",

packaging/types.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
# Regenerates lib/types.d.ts Typescript definitions
4+
sources="lib/constructor.js lib/input.js lib/resize.js lib/composite.js lib/operation.js lib/colour.js lib/channel.js lib/output.js lib/utility.js"
5+
types="types.d.ts"
6+
7+
# Generate types via JSDoc comments
8+
./node_modules/.bin/jsdoc -d . -t ./node_modules/tsd-jsdoc $sources
9+
10+
# Wrap output with module declaration
11+
echo "declare module \"sharp\" {\n" > "lib/$types"
12+
cat "$types" >> "lib/$types"
13+
echo "}\n" >> "lib/$types"
14+
rm "$types"

0 commit comments

Comments
 (0)