From ed0a73fbb2dd6d016b3546ab01cf8ef5dd512063 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 28 Sep 2017 09:14:42 -0700 Subject: [PATCH] Strict function variance fixes round 1, stage 1 --- types/backbone/index.d.ts | 2 +- types/bootbox/index.d.ts | 14 +++++++------- types/bootbox/tsconfig.json | 3 ++- types/cordova-plugin-inappbrowser/index.d.ts | 2 +- types/cordova-plugin-inappbrowser/tsconfig.json | 3 ++- types/ibm-mobilefirst/index.d.ts | 4 ++-- types/ibm-mobilefirst/tsconfig.json | 3 ++- types/q/q-tests.ts | 10 +++++----- types/q/tsconfig.json | 1 + types/react/index.d.ts | 6 +++--- types/react/tsconfig.json | 1 + 11 files changed, 27 insertions(+), 22 deletions(-) diff --git a/types/backbone/index.d.ts b/types/backbone/index.d.ts index 806086943e..42a322e4c2 100644 --- a/types/backbone/index.d.ts +++ b/types/backbone/index.d.ts @@ -219,7 +219,7 @@ declare namespace Backbone { /** * Specify a model attribute name (string) or function that will be used to sort the collection. */ - comparator: string | ((element: TModel) => number | string) | ((compare: TModel, to?: TModel) => number); + comparator: string | { bivarianceHack(element: TModel): number | string }["bivarianceHack"] | { bivarianceHack(compare: TModel, to?: TModel): number }["bivarianceHack"]; add(model: {}|TModel, options?: AddOptions): TModel; add(models: ({}|TModel)[], options?: AddOptions): TModel[]; diff --git a/types/bootbox/index.d.ts b/types/bootbox/index.d.ts index ba5cc8c23b..c2fe427d6c 100644 --- a/types/bootbox/index.d.ts +++ b/types/bootbox/index.d.ts @@ -7,9 +7,9 @@ /// /** Bootbox options shared by all modal types */ -interface BootboxBaseOptions { +interface BootboxBaseOptions { title?: string | Element; - callback?: (result: boolean | string) => any; + callback?: (result: T) => any; onEscape?: (() => any) | boolean; show?: boolean; backdrop?: boolean; @@ -22,24 +22,24 @@ interface BootboxBaseOptions { } /** Bootbox options available for custom modals */ -interface BootboxDialogOptions extends BootboxBaseOptions { +interface BootboxDialogOptions extends BootboxBaseOptions { message: string | Element; } /** Bootbox options available for alert modals */ -interface BootboxAlertOptions extends BootboxDialogOptions { +interface BootboxAlertOptions extends BootboxDialogOptions { callback?: () => any; buttons?: BootboxAlertButtonMap; } /** Bootbox options available for confirm modals */ -interface BootboxConfirmOptions extends BootboxDialogOptions { +interface BootboxConfirmOptions extends BootboxDialogOptions { callback: (result: boolean) => any; buttons?: BootboxConfirmPromptButtonMap; } /** Bootbox options available for prompt modals */ -interface BootboxPromptOptions extends BootboxBaseOptions { +interface BootboxPromptOptions extends BootboxBaseOptions { title: string; value?: string; inputType?: "text" | "textarea" | "email" | "select" | "checkbox" | "date" | "time" | "number" | "password"; @@ -93,7 +93,7 @@ interface BootboxStatic { prompt(message: string, callback: (result: string) => void): JQuery; prompt(options: BootboxPromptOptions): JQuery; dialog(message: string, callback?: (result: string) => void): JQuery; - dialog(options: BootboxDialogOptions): JQuery; + dialog(options: BootboxDialogOptions): JQuery; setDefaults(options: BootboxDefaultOptions): void; hideAll(): void; diff --git a/types/bootbox/tsconfig.json b/types/bootbox/tsconfig.json index e9bedd04f7..3ac9d8b49d 100644 --- a/types/bootbox/tsconfig.json +++ b/types/bootbox/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": false, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" @@ -20,4 +21,4 @@ "index.d.ts", "bootbox-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/cordova-plugin-inappbrowser/index.d.ts b/types/cordova-plugin-inappbrowser/index.d.ts index b266fbab44..1cf2c67642 100644 --- a/types/cordova-plugin-inappbrowser/index.d.ts +++ b/types/cordova-plugin-inappbrowser/index.d.ts @@ -25,7 +25,7 @@ interface Window { * NOTE: The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs. */ interface InAppBrowser extends Window { - onloadstart(type: InAppBrowserEvent): void; + onloadstart(type: Event): void; onloadstop(type: InAppBrowserEvent): void; onloaderror(type: InAppBrowserEvent): void; onexit(type: InAppBrowserEvent): void; diff --git a/types/cordova-plugin-inappbrowser/tsconfig.json b/types/cordova-plugin-inappbrowser/tsconfig.json index fc11c3516e..2e42f7997b 100644 --- a/types/cordova-plugin-inappbrowser/tsconfig.json +++ b/types/cordova-plugin-inappbrowser/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": false, "noImplicitThis": true, "strictNullChecks": false, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" @@ -20,4 +21,4 @@ "index.d.ts", "cordova-plugin-inappbrowser-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/ibm-mobilefirst/index.d.ts b/types/ibm-mobilefirst/index.d.ts index 4da0cbf3b1..2577b0972b 100644 --- a/types/ibm-mobilefirst/index.d.ts +++ b/types/ibm-mobilefirst/index.d.ts @@ -61,8 +61,8 @@ declare namespace WL { getHeader(name: any): string; } interface Options { - onSuccess?: (response: IResponse) => void; - onFailure?: (response: IResponse) => void; + onSuccess?(response: IResponse): void; + onFailure?(response: IResponse): void; invocationContext?: any; } interface ResponseHandler { diff --git a/types/ibm-mobilefirst/tsconfig.json b/types/ibm-mobilefirst/tsconfig.json index 0e4e6e45d9..86307e821b 100644 --- a/types/ibm-mobilefirst/tsconfig.json +++ b/types/ibm-mobilefirst/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": false, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" @@ -20,4 +21,4 @@ "index.d.ts", "ibm-mobilefirst-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/q/q-tests.ts b/types/q/q-tests.ts index cb9e46e5a7..f54f913e07 100644 --- a/types/q/q-tests.ts +++ b/types/q/q-tests.ts @@ -144,13 +144,13 @@ const nodeStyle = (input: string, cb: (error: any, success: any) => void) => { cb(null, input); }; -Q.nfapply(nodeStyle, ["foo"]).done((result: string) => { +Q.nfapply(nodeStyle, ["foo"]).done((result: string) => { }); -Q.nfcall(nodeStyle, "foo").done((result: string) => { +Q.nfcall(nodeStyle, "foo").done((result: string) => { }); -Q.denodeify(nodeStyle)('foo').done((result: string) => { +Q.denodeify(nodeStyle)('foo').done((result: string) => { }); -Q.nfbind(nodeStyle)('foo').done((result: string) => { +Q.nfbind(nodeStyle)('foo').done((result: string) => { }); class Repo { @@ -171,7 +171,7 @@ class Repo { } const kitty = new Repo(); -Q.nbind(kitty.find, kitty)({cute: true}).done((kitties: any[]) => { +Q.nbind(kitty.find, kitty)({cute: true}).done((kitties: any[]) => { }); /** diff --git a/types/q/tsconfig.json b/types/q/tsconfig.json index 12c105d622..40c079d929 100644 --- a/types/q/tsconfig.json +++ b/types/q/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": false, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 56d417319a..f7ce03ec91 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -72,7 +72,7 @@ declare namespace React { type ComponentType

= ComponentClass

| StatelessComponent

; type Key = string | number; - type Ref = string | ((instance: T | null) => any); + type Ref = string | { bivarianceHack(instance: T | null): any }["bivarianceHack"]; // tslint:disable-next-line:interface-over-type-literal type ComponentState = {}; @@ -555,7 +555,7 @@ declare namespace React { // Event Handler Types // ---------------------------------------------------------------------- - type EventHandler> = (event: E) => void; + type EventHandler> = { bivarianceHack(event: E): void }["bivarianceHack"]; type ReactEventHandler = EventHandler>; @@ -3369,7 +3369,7 @@ declare namespace React { // React.PropTypes // ---------------------------------------------------------------------- - type Validator = (object: T, key: string, componentName: string, ...rest: any[]) => Error | null; + type Validator = { bivarianceHack(object: T, key: string, componentName: string, ...rest: any[]): Error | null }["bivarianceHack"]; interface Requireable extends Validator { isRequired: Validator; diff --git a/types/react/tsconfig.json b/types/react/tsconfig.json index d2c4600811..4c27ed5e21 100644 --- a/types/react/tsconfig.json +++ b/types/react/tsconfig.json @@ -14,6 +14,7 @@ "noImplicitAny": true, "noImplicitThis": false, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../"