From 5c883834e362f2c08a0cf405a2e0a8bbf4020c6e Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Fri, 27 Mar 2020 16:59:51 +0100 Subject: [PATCH] =?UTF-8?q?feat(webidl=E2=80=91conversions):=20Update?= =?UTF-8?q?=C2=A0to=C2=A0v6.0=20(#43334)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/webidl-conversions/index.d.ts | 15 ++++++++++++--- types/webidl-conversions/tsconfig.json | 12 ++++-------- .../webidl-conversions-tests.ts | 13 +++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/types/webidl-conversions/index.d.ts b/types/webidl-conversions/index.d.ts index 92919dfe87..d3197f29fd 100644 --- a/types/webidl-conversions/index.d.ts +++ b/types/webidl-conversions/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for webidl-conversions 5.0 +// Type definitions for webidl-conversions 6.0 // Project: https://github.com/jsdom/webidl-conversions#readme // Definitions by: ExE Boss // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -7,8 +7,17 @@ type Parameters any> = T extends (...args: infer P) => any ? P : never; declare namespace WebIDLConversions { + interface Globals { + [key: string]: any; + + Number: (value?: any) => number; + String: (value?: any) => string; + TypeError: new (message?: string) => TypeError; + } + interface Options { context?: string; + globals?: Globals; } interface IntegerOptions extends Options { @@ -73,11 +82,11 @@ declare const WebIDLConversions: { DOMTimeStamp(V: any, opts?: WebIDLConversions.Options): number; // tslint:disable:ban-types - Function(V: V, opts?: WebIDLConversions.Options): V extends ((...args: any[]) => any) ? V : Function; + Function(V: V, opts?: WebIDLConversions.Options): V extends (...args: any[]) => any ? V : Function; VoidFunction( V: V, opts?: WebIDLConversions.Options, - ): V extends ((...args: any[]) => any) ? (...args: Parameters) => void : Function; + ): V extends (...args: any[]) => any ? (...args: Parameters) => void : Function; }; // This can't use ES6 style exports, as those can't have spaces in export names. diff --git a/types/webidl-conversions/tsconfig.json b/types/webidl-conversions/tsconfig.json index efe968e66b..ee3ca768d8 100644 --- a/types/webidl-conversions/tsconfig.json +++ b/types/webidl-conversions/tsconfig.json @@ -1,23 +1,19 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es2015" - ], + "lib": ["es2015"], "noImplicitAny": true, "noImplicitThis": true, "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts", - "webidl-conversions-tests.ts" + "webidl-conversions-tests.ts", + "index.d.ts" ] } diff --git a/types/webidl-conversions/webidl-conversions-tests.ts b/types/webidl-conversions/webidl-conversions-tests.ts index 08719c3d5b..c26a3716a5 100644 --- a/types/webidl-conversions/webidl-conversions-tests.ts +++ b/types/webidl-conversions/webidl-conversions-tests.ts @@ -7,6 +7,19 @@ const options: conversions.Options = ((): conversions.Options => { return {}; })(); +options.context; // $ExpectType string | undefined + +const { + globals, // $ExpectType Globals | undefined +} = options; + +if (globals) { + globals; // $ExpectType Globals + globals.Number; // $ExpectType (value?: any) => number + globals.String; // $ExpectType (value?: any) => string + globals.TypeError; // $ExpectType new (message?: string | undefined) => TypeError +} + /** * The `expectType` function from https://www.npmjs.com/package/tsd, * except instead of returning `void`, it returns `T`.