diff --git a/lib/types.d.ts b/lib/types.d.ts index 9920ce7b..7b1d471d 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -1,3 +1,5 @@ +declare module "sharp" { + /** * @class Sharp * @@ -202,7 +204,7 @@ declare function clone(): Sharp; * @param {Function} [callback] - called with the arguments `(err, metadata)` * @returns {Promise|Sharp} */ -declare function metadata(callback?: (() => any)): (Promise.|Sharp); +declare function metadata(callback?: (() => any)): (Promise|Sharp); /** * 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; * @returns {Promise} - when no callback is provided * @throws {Error} Invalid parameters */ -declare function toFile(fileOut: String, callback?: (() => any)): Promise.; +declare function toFile(fileOut: String, callback?: (() => any)): Promise; /** * Write output to a Buffer. @@ -806,7 +808,7 @@ declare function toFile(fileOut: String, callback?: (() => any)): Promise.} - when no callback is provided */ -declare function toBuffer(callback?: (() => any)): Promise.; +declare function toBuffer(callback?: (() => any)): Promise; /** * Include all metadata (EXIF, XMP, IPTC) from the input image in the output image. @@ -1017,3 +1019,5 @@ declare function counters(): Object; */ declare function simd(simd?: Boolean): Boolean; +} + diff --git a/package.json b/package.json index cf9b943e..6497ca5b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packaging/types.sh b/packaging/types.sh new file mode 100755 index 00000000..1751256e --- /dev/null +++ b/packaging/types.sh @@ -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"