From e72b790b6897d202602ec5cb2c69a4a3e918b2a3 Mon Sep 17 00:00:00 2001 From: Chen Date: Tue, 3 Mar 2020 01:33:37 +0800 Subject: [PATCH] chai: Tighten argument types of assert.throw methods. (#42719) * Refine argument types of assert.thorw methods. * Add author. --- types/chai/index.d.ts | 55 ++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index ce3cb8c308..f649bee49e 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -5,12 +5,13 @@ // Andrew Brown , // Olivier Chevet , // Matt Wistrand , -// Josh Goldberg -// Shaun Luttin -// Gintautas Miselis -// Satana Charuwichitratana -// Erik Schierboom -// Bogdan Paranytsia +// Josh Goldberg , +// Shaun Luttin , +// Gintautas Miselis , +// Satana Charuwichitratana , +// Erik Schierboom , +// Bogdan Paranytsia , +// CXuesong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -130,7 +131,7 @@ declare namespace Chai { export interface AssertionStatic extends AssertionPrototype { prototype: AssertionPrototype; - new (target: any, message?: string, ssfi?: Function, lockSsfi?: boolean): Assertion; + new(target: any, message?: string, ssfi?: Function, lockSsfi?: boolean): Assertion; // Deprecated properties: includeStack: boolean; @@ -170,8 +171,8 @@ declare namespace Chai { } interface ShouldThrow { - (actual: Function, expected?: string|RegExp, message?: string): void; - (actual: Function, constructor: Error|Function, expected?: string|RegExp, message?: string): void; + (actual: Function, expected?: string | RegExp, message?: string): void; + (actual: Function, constructor: Error | Function, expected?: string | RegExp, message?: string): void; } interface Assertion extends LanguageChains, NumericComparison, TypeComparison { @@ -364,12 +365,12 @@ declare namespace Chai { interface Keys { (...keys: string[]): Assertion; - (keys: ReadonlyArray|Object): Assertion; + (keys: ReadonlyArray | Object): Assertion; } interface Throw { - (expected?: string|RegExp, message?: string): Assertion; - (constructor: Error|Function, expected?: string|RegExp, message?: string): Assertion; + (expected?: string | RegExp, message?: string): Assertion; + (constructor: Error | Function, expected?: string | RegExp, message?: string): Assertion; } interface RespondTo { @@ -1170,7 +1171,7 @@ declare namespace Chai { * @param fn Function that may throw. * @param message Message to display on error. */ - throw(fn: Function, message?: string): void; + throw(fn: () => void, message?: string): void; /** * Asserts that function will throw an error with message matching regexp. @@ -1179,7 +1180,7 @@ declare namespace Chai { * @param regExp Potential expected message match. * @param message Message to display on error. */ - throw(fn: Function, regExp: RegExp): void; + throw(fn: () => void, regExp: RegExp): void; /** * Asserts that function will throw an error that is an instance of constructor. @@ -1188,7 +1189,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - throw(fn: Function, constructor: Function, message?: string): void; + throw(fn: () => void, constructor: ErrorConstructor, message?: string): void; /** * Asserts that function will throw an error that is an instance of constructor @@ -1198,7 +1199,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - throw(fn: Function, constructor: Function, regExp: RegExp): void; + throw(fn: () => void, constructor: ErrorConstructor, regExp: RegExp): void; /** * Asserts that fn will throw an error. @@ -1206,7 +1207,7 @@ declare namespace Chai { * @param fn Function that may throw. * @param message Message to display on error. */ - throws(fn: Function, message?: string): void; + throws(fn: () => void, message?: string): void; /** * Asserts that function will throw an error with message matching regexp. @@ -1215,7 +1216,7 @@ declare namespace Chai { * @param errType Potential expected message match or error constructor. * @param message Message to display on error. */ - throws(fn: Function, errType: RegExp|Function, message?: string): void; + throws(fn: () => void, errType: RegExp | ErrorConstructor, message?: string): void; /** * Asserts that function will throw an error that is an instance of constructor @@ -1225,7 +1226,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - throws(fn: Function, errType: Function, regExp: RegExp): void; + throws(fn: () => void, constructor: ErrorConstructor, regExp: RegExp): void; /** * Asserts that fn will throw an error. @@ -1233,7 +1234,7 @@ declare namespace Chai { * @param fn Function that may throw. * @param message Message to display on error. */ - Throw(fn: Function, message?: string): void; + Throw(fn: () => void, message?: string): void; /** * Asserts that function will throw an error with message matching regexp. @@ -1242,7 +1243,7 @@ declare namespace Chai { * @param regExp Potential expected message match. * @param message Message to display on error. */ - Throw(fn: Function, regExp: RegExp): void; + Throw(fn: () => void, regExp: RegExp): void; /** * Asserts that function will throw an error that is an instance of constructor. @@ -1251,7 +1252,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - Throw(fn: Function, errType: Function, message?: string): void; + Throw(fn: () => void, constructor: ErrorConstructor, message?: string): void; /** * Asserts that function will throw an error that is an instance of constructor @@ -1261,7 +1262,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - Throw(fn: Function, errType: Function, regExp: RegExp): void; + Throw(fn: () => void, constructor: ErrorConstructor, regExp: RegExp): void; /** * Asserts that fn will not throw an error. @@ -1269,7 +1270,7 @@ declare namespace Chai { * @param fn Function that may throw. * @param message Message to display on error. */ - doesNotThrow(fn: Function, message?: string): void; + doesNotThrow(fn: () => void, message?: string): void; /** * Asserts that function will throw an error with message matching regexp. @@ -1278,7 +1279,7 @@ declare namespace Chai { * @param regExp Potential expected message match. * @param message Message to display on error. */ - doesNotThrow(fn: Function, regExp: RegExp): void; + doesNotThrow(fn: () => void, regExp: RegExp): void; /** * Asserts that function will throw an error that is an instance of constructor. @@ -1287,7 +1288,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - doesNotThrow(fn: Function, errType: Function, message?: string): void; + doesNotThrow(fn: () => void, constructor: ErrorConstructor, message?: string): void; /** * Asserts that function will throw an error that is an instance of constructor @@ -1297,7 +1298,7 @@ declare namespace Chai { * @param constructor Potential expected error constructor. * @param message Message to display on error. */ - doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void; + doesNotThrow(fn: () => void, constructor: ErrorConstructor, regExp: RegExp): void; /** * Compares two values using operator.