From 5b2eb2d8728caaf71230699bc2ebd9c2735ac119 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Mon, 19 Jun 2017 13:36:58 -0400 Subject: [PATCH] [jquery] Fix imported JQueryStatic not returning a JQuery object when called with window. --- types/jquery/index.d.ts | 4 ++-- types/jquery/test/jquery-no-window-module-tests.ts | 8 ++++++++ types/jquery/test/jquery-slim-no-window-module-tests.ts | 8 ++++++++ types/jquery/test/jquery-slim-window-module-tests.ts | 8 ++++++++ types/jquery/test/jquery-window-module-tests.ts | 8 ++++++++ types/jquery/test/module-tests.ts | 7 ------- types/jquery/tsconfig.json | 5 ++++- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 types/jquery/test/jquery-no-window-module-tests.ts create mode 100644 types/jquery/test/jquery-slim-no-window-module-tests.ts create mode 100644 types/jquery/test/jquery-slim-window-module-tests.ts create mode 100644 types/jquery/test/jquery-window-module-tests.ts delete mode 100644 types/jquery/test/module-tests.ts diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 48bf0ab6ba..cea056ef60 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -25,14 +25,14 @@ // TypeScript Version: 2.3 declare module 'jquery' { - function factory(window: Window): JQueryStatic; + function factory(window: Window): JQueryStatic & JQuery; const factoryOrJQuery: typeof factory & JQueryStatic; export = factoryOrJQuery; } declare module 'jquery/dist/jquery.slim' { - function factory(window: Window): JQueryStatic; + function factory(window: Window): JQueryStatic & JQuery; const factoryOrJQuery: typeof factory & JQueryStatic; export = factoryOrJQuery; diff --git a/types/jquery/test/jquery-no-window-module-tests.ts b/types/jquery/test/jquery-no-window-module-tests.ts new file mode 100644 index 0000000000..700be9d60c --- /dev/null +++ b/types/jquery/test/jquery-no-window-module-tests.ts @@ -0,0 +1,8 @@ +import jQueryFactory = require('jquery'); + +const jq = jQueryFactory(window); +// ExpectType will report 'jq' as 'JQueryStatic & JQuery' even though the compiler seems to know that 'jq' is 'JQueryStatic' +// // $ExpectType JQueryStatic +// jq; +// jq === jQuery(); +jq === jQuery; diff --git a/types/jquery/test/jquery-slim-no-window-module-tests.ts b/types/jquery/test/jquery-slim-no-window-module-tests.ts new file mode 100644 index 0000000000..fdbd34e06c --- /dev/null +++ b/types/jquery/test/jquery-slim-no-window-module-tests.ts @@ -0,0 +1,8 @@ +import jQueryFactory = require('jquery/dist/jquery.slim'); + +const jq = jQueryFactory(window); +// ExpectType will report 'jq' as 'JQueryStatic & JQuery' even though the compiler seems to know that 'jq' is 'JQueryStatic' +// // $ExpectType JQueryStatic +// jq; +// jq === jQuery(); +jq === jQuery; diff --git a/types/jquery/test/jquery-slim-window-module-tests.ts b/types/jquery/test/jquery-slim-window-module-tests.ts new file mode 100644 index 0000000000..8072811f08 --- /dev/null +++ b/types/jquery/test/jquery-slim-window-module-tests.ts @@ -0,0 +1,8 @@ +import * as jq from 'jquery/dist/jquery.slim'; + +const $window = jq(window); +// ExpectType will report 'jq' as 'JQueryStatic & JQuery' even though the compiler seems to know that 'jq' is 'JQuery' +// // $ExpectType JQuery +// $window; +// $window === jq; +$window === jq(); diff --git a/types/jquery/test/jquery-window-module-tests.ts b/types/jquery/test/jquery-window-module-tests.ts new file mode 100644 index 0000000000..85f2c4c4ea --- /dev/null +++ b/types/jquery/test/jquery-window-module-tests.ts @@ -0,0 +1,8 @@ +import * as jq from 'jquery'; + +const $window = jq(window); +// ExpectType will report 'jq' as 'JQueryStatic & JQuery' even though the compiler seems to know that 'jq' is 'JQuery' +// // $ExpectType JQuery +// $window; +// $window === jq; +$window === jq(); diff --git a/types/jquery/test/module-tests.ts b/types/jquery/test/module-tests.ts deleted file mode 100644 index b55dee0370..0000000000 --- a/types/jquery/test/module-tests.ts +++ /dev/null @@ -1,7 +0,0 @@ -import factory = require('jquery'); -const jq = factory(window); -jq.noop(); - -import slimFactory = require('jquery/dist/jquery.slim'); -const slim = slimFactory(window); -slim.noop(); diff --git a/types/jquery/tsconfig.json b/types/jquery/tsconfig.json index ebfa01c813..21d35a63da 100644 --- a/types/jquery/tsconfig.json +++ b/types/jquery/tsconfig.json @@ -22,6 +22,9 @@ "jquery-tests.ts", "test/example-tests.ts", "test/longdesc-tests.ts", - "test/module-tests.ts" + "test/jquery-no-window-module-tests.ts", + "test/jquery-window-module-tests.ts", + "test/jquery-slim-no-window-module-tests.ts", + "test/jquery-slim-window-module-tests.ts" ] }