diff --git a/types/sha1/index.d.ts b/types/sha1/index.d.ts index bb55d2f4fc..b65c456054 100644 --- a/types/sha1/index.d.ts +++ b/types/sha1/index.d.ts @@ -12,10 +12,19 @@ * @param options - an options object * @returns the resultant SHA1 hash of the given message */ +declare function main(message: string | Buffer, options?: Sha1AsStringOptions): string; +declare function main(message: string | Buffer, options?: Sha1AsBytesOptions): Uint8Array; declare function main(message: string | Buffer, options?: Sha1Options): string | Uint8Array; export = main; -interface Sha1Options { - asBytes?: boolean; +interface Sha1AsStringOptions { + asBytes?: false; asString?: boolean; } + +interface Sha1AsBytesOptions { + asBytes: true; + asString?: false; +} + +type Sha1Options = Sha1AsStringOptions | Sha1AsBytesOptions; diff --git a/types/sha1/sha1-tests.ts b/types/sha1/sha1-tests.ts index 6ce833b10b..12feb5b3d8 100644 --- a/types/sha1/sha1-tests.ts +++ b/types/sha1/sha1-tests.ts @@ -9,3 +9,7 @@ const testThree = sha1('message', {asBytes: true}); fs.readFile('sha1.d.ts', (err: Error, buf: Buffer) => { console.log(sha1(buf)); }); + +const asHexString: string = sha1('message'); +const asBinString: string = sha1('message', {asString: true}); +const asBytes: Uint8Array = sha1('message', {asBytes: true});