Skip to content

Commit

Permalink
Move lib/types.d.ts generation to separate script.
Browse files Browse the repository at this point in the history
Fixes Promise<T>, ensures module prefix is declared.
  • Loading branch information
lovell committed Nov 20, 2016
1 parent effa77a commit e4e7384
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
declare module "sharp" {

/**
* @class Sharp
*
Expand Down Expand Up @@ -202,7 +204,7 @@ declare function clone(): Sharp;
* @param {Function} [callback] - called with the arguments `(err, metadata)`
* @returns {Promise<Object>|Sharp}
*/
declare function metadata(callback?: (() => any)): (Promise.<Object>|Sharp);
declare function metadata(callback?: (() => any)): (Promise<Object>|Sharp);

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

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

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

}

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test-leak": "./test/leak/leak.sh",
"test-packaging": "./packaging/test-linux-x64.sh",
"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",
"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"
"types": "./packaging/types.sh"
},
"main": "lib/index.js",
"types": "lib/types.d.ts",
Expand Down Expand Up @@ -81,7 +81,7 @@
"nyc": "^9.0.1",
"rimraf": "^2.5.4",
"semistandard": "^9.1.0",
"tsd-jsdoc": "^1.0.1",
"tsd-jsdoc": "lovell/tsd-jsdoc#add-support-for-promises",
"unzip": "^0.1.11"
},
"license": "Apache-2.0",
Expand Down
14 changes: 14 additions & 0 deletions packaging/types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# Regenerates lib/types.d.ts Typescript definitions
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"
types="types.d.ts"

# Generate types via JSDoc comments
./node_modules/.bin/jsdoc -d . -t ./node_modules/tsd-jsdoc $sources

# Wrap output with module declaration
echo "declare module \"sharp\" {\n" > "lib/$types"
cat "$types" >> "lib/$types"
echo "}\n" >> "lib/$types"
rm "$types"

0 comments on commit e4e7384

Please sign in to comment.