From 38728d9cc8d956d6a1c391a2a0e99a8236923699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 16 Oct 2018 13:57:01 +0200 Subject: [PATCH 001/792] description --- types/range-parser/index.d.ts | 4 ++-- types/range-parser/tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/range-parser/index.d.ts b/types/range-parser/index.d.ts index a1bcf4c9dc..13d331041a 100644 --- a/types/range-parser/index.d.ts +++ b/types/range-parser/index.d.ts @@ -4,11 +4,11 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** - * Returns `-1` when unsatisfiable and `-2` when syntactically invalid. - * * When ranges are returned, the array has a "type" property which is the type of * range that is required (most commonly, "bytes"). Each array element is an object * with a "start" and "end" property for the portion of the range. + * + * @returns `-1` when unsatisfiable and `-2` when syntactically invalid, ranges otherwise. */ declare function RangeParser(size: number, str: string, options?: RangeParser.Options): RangeParser.Result | RangeParser.Ranges; diff --git a/types/range-parser/tsconfig.json b/types/range-parser/tsconfig.json index 15585886a9..dc6de494bf 100644 --- a/types/range-parser/tsconfig.json +++ b/types/range-parser/tsconfig.json @@ -20,4 +20,4 @@ "index.d.ts", "range-parser-tests.ts" ] -} \ No newline at end of file +} From 6d51909cafaad3b3634ad057bfeb2f7eac011872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 16 Oct 2018 14:10:42 +0200 Subject: [PATCH 002/792] --isolatedModules fix --- types/range-parser/index.d.ts | 7 +++---- types/range-parser/range-parser-tests.ts | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/types/range-parser/index.d.ts b/types/range-parser/index.d.ts index 13d331041a..e8e6ae4451 100644 --- a/types/range-parser/index.d.ts +++ b/types/range-parser/index.d.ts @@ -27,10 +27,9 @@ declare namespace RangeParser { */ combine?: boolean; } - const enum Result { - invaild = -2, - unsatisifiable = -1, - } + type ResultUnsatisfiable = -1; + type ResultInvalid = -2; + type Result = ResultUnsatisfiable | ResultInvalid; } export = RangeParser; diff --git a/types/range-parser/range-parser-tests.ts b/types/range-parser/range-parser-tests.ts index ec1ffa6e4e..2c18e3f9dc 100644 --- a/types/range-parser/range-parser-tests.ts +++ b/types/range-parser/range-parser-tests.ts @@ -2,8 +2,8 @@ import RangeParser = require('range-parser'); declare var console: { assert(b: boolean): void }; -console.assert(RangeParser(200, `malformed`) === RangeParser.Result.invaild); -console.assert(RangeParser(200, `bytes=500-20`) === RangeParser.Result.unsatisifiable); +console.assert(RangeParser(200, `malformed`) === -2); +console.assert(RangeParser(200, `bytes=500-20`) === -1); const range = RangeParser(1000, `bytes=0-499`); From 202f4ee2dd0603bc665629d5f6c1c37ae3868dd6 Mon Sep 17 00:00:00 2001 From: Jeff Held Date: Thu, 8 Nov 2018 16:49:37 -0600 Subject: [PATCH 003/792] detox: create tests folder, add test for importing Detox module --- types/detox/detox-tests.ts | 31 -------------- types/detox/tests/detox-globals-tests.ts | 40 ++++++++++++++++++ .../detox/tests/detox-import-modules-tests.ts | 42 +++++++++++++++++++ types/detox/tsconfig.json | 11 ++--- 4 files changed, 86 insertions(+), 38 deletions(-) delete mode 100644 types/detox/detox-tests.ts create mode 100644 types/detox/tests/detox-globals-tests.ts create mode 100644 types/detox/tests/detox-import-modules-tests.ts diff --git a/types/detox/detox-tests.ts b/types/detox/detox-tests.ts deleted file mode 100644 index 58fe5c1912..0000000000 --- a/types/detox/detox-tests.ts +++ /dev/null @@ -1,31 +0,0 @@ -declare var describe: (test: string, callback: () => void) => void; -declare var beforeAll: (callback: () => void) => void; -declare var afterAll: (callback: () => void) => void; -declare var test: (test: string, callback: () => void) => void; - -describe('Test', () => { - beforeAll(async () => { - await device.reloadReactNative(); - }); - - afterAll(async () => { - await element(by.id('element')).clearText(); - }); - - test('Test', async () => { - await element(by.id('element')).replaceText('text'); - await element(by.id('element')).tap(); - await element(by.id('element')).scroll(50, 'down'); - await element(by.id('scrollView')).scrollTo('bottom'); - await expect(element(by.id('element')).atIndex(0)).toNotExist(); - await element(by.id('scrollView')).swipe('down', 'fast'); - await element(by.type('UIPickerView')).setColumnToValue(1, "6"); - - await expect(element(by.id('element').withAncestor(by.id('parent_element')))).toNotExist(); - await expect(element(by.id('element').withDescendant(by.id('child_element')))).toNotExist(); - - await waitFor(element(by.id('element'))).toBeVisible().withTimeout(2000); - await device.pressBack(); - await waitFor(element(by.text('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down'); - }); -}); diff --git a/types/detox/tests/detox-globals-tests.ts b/types/detox/tests/detox-globals-tests.ts new file mode 100644 index 0000000000..42415c548d --- /dev/null +++ b/types/detox/tests/detox-globals-tests.ts @@ -0,0 +1,40 @@ +declare var describe: (test: string, callback: () => void) => void; +declare var beforeAll: (callback: () => void) => void; +declare var afterAll: (callback: () => void) => void; +declare var test: (test: string, callback: () => void) => void; + +describe("Test", () => { + beforeAll(async () => { + await device.reloadReactNative(); + }); + + afterAll(async () => { + await element(by.id("element")).clearText(); + }); + + test("Test", async () => { + await element(by.id("element")).replaceText("text"); + await element(by.id("element")).tap(); + await element(by.id("element")).scroll(50, "down"); + await element(by.id("scrollView")).scrollTo("bottom"); + await expect(element(by.id("element")).atIndex(0)).toNotExist(); + await element(by.id("scrollView")).swipe("down", "fast"); + await element(by.type("UIPickerView")).setColumnToValue(1, "6"); + + await expect( + element(by.id("element").withAncestor(by.id("parent_element"))) + ).toNotExist(); + await expect( + element(by.id("element").withDescendant(by.id("child_element"))) + ).toNotExist(); + + await waitFor(element(by.id("element"))) + .toBeVisible() + .withTimeout(2000); + await device.pressBack(); + await waitFor(element(by.text("Text5"))) + .toBeVisible() + .whileElement(by.id("ScrollView630")) + .scroll(50, "down"); + }); +}); diff --git a/types/detox/tests/detox-import-modules-tests.ts b/types/detox/tests/detox-import-modules-tests.ts new file mode 100644 index 0000000000..318569c03d --- /dev/null +++ b/types/detox/tests/detox-import-modules-tests.ts @@ -0,0 +1,42 @@ +declare var describe: (test: string, callback: () => void) => void; +declare var beforeAll: (callback: () => void) => void; +declare var afterAll: (callback: () => void) => void; +declare var test: (test: string, callback: () => void) => void; + +import { by, device, element, expect, waitFor } from "detox"; + +describe("Test", () => { + beforeAll(async () => { + await device.reloadReactNative(); + }); + + afterAll(async () => { + await element(by.id("element")).clearText(); + }); + + test("Test", async () => { + await element(by.id("element")).replaceText("text"); + await element(by.id("element")).tap(); + await element(by.id("element")).scroll(50, "down"); + await element(by.id("scrollView")).scrollTo("bottom"); + await expect(element(by.id("element")).atIndex(0)).toNotExist(); + await element(by.id("scrollView")).swipe("down", "fast"); + await element(by.type("UIPickerView")).setColumnToValue(1, "6"); + + await expect( + element(by.id("element").withAncestor(by.id("parent_element"))) + ).toNotExist(); + await expect( + element(by.id("element").withDescendant(by.id("child_element"))) + ).toNotExist(); + + await waitFor(element(by.id("element"))) + .toBeVisible() + .withTimeout(2000); + await device.pressBack(); + await waitFor(element(by.text("Text5"))) + .toBeVisible() + .whileElement(by.id("ScrollView630")) + .scroll(50, "down"); + }); +}); diff --git a/types/detox/tsconfig.json b/types/detox/tsconfig.json index 2d1a22fb79..3eb7524be2 100644 --- a/types/detox/tsconfig.json +++ b/types/detox/tsconfig.json @@ -1,24 +1,21 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6" - ], + "lib": ["es6"], "target": "ES2015", "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", - "detox-tests.ts" + "tests/detox-globals-tests.ts", + "tests/detox-import-modules-tests.ts" ] } From 45a0c57ef040ed95fa5994b05a2a5c32778706fc Mon Sep 17 00:00:00 2001 From: Jeff Held Date: Thu, 8 Nov 2018 16:49:42 -0600 Subject: [PATCH 004/792] detox: follow global-modifying dts example --- types/detox/index.d.ts | 821 +++++++++++++++++++++-------------------- 1 file changed, 416 insertions(+), 405 deletions(-) diff --git a/types/detox/index.d.ts b/types/detox/index.d.ts index 7ef085e25d..f9baa99f6e 100644 --- a/types/detox/index.d.ts +++ b/types/detox/index.d.ts @@ -3,418 +3,429 @@ // Definitions by: Tareq El-Masri , Steve Chun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare const detox: Detox.Detox; -declare const device: Detox.Device; -declare const element: Detox.Element; -declare const waitFor: Detox.WaitFor; -declare const expect: Detox.Expect>; -declare const by: Detox.Matchers; +declare global { + const detox: Detox.Detox; + const device: Detox.Device; + const element: Detox.Element; + const waitFor: Detox.WaitFor; + const expect: Detox.Expect>; + const by: Detox.Matchers; -declare namespace Detox { - interface Detox { - /** - * The setup phase happens inside detox.init(). This is the phase where detox reads its configuration, starts a server, loads its expection library and starts a simulator - * @param config - * @param options - * @example const config = require('../package.json').detox; - * - * before(async () => { - * await detox.init(config); - * }); - */ - init(config: any, options?: DetoxInitOptions): Promise; - /** - * Artifacts currently include only logs from the app process before each task - * @param args - */ - beforeEach(...args: any[]): Promise; - /** - * Artifacts currently include only logs from the app process after each task - * @param args - */ - afterEach(...args: any[]): Promise; - /** - * The cleanup phase should happen after all the tests have finished. This is the phase where detox-server shuts down. - * @example after(async () => { - * await detox.cleanup(); - * }); - */ - cleanup(): Promise; - } - interface Device { - /** - * Launch the app - * @param config - * @example // Terminate the app and launch it again. If set to false, the simulator will try to bring app from background, - * // if the app isn't running, it will launch a new instance. default is false - * await device.launchApp({newInstance: true}); - * // Grant or deny runtime permissions for your application. - * await device.launchApp({permissions: {calendar: 'YES'}}); - * // Mock opening the app from URL to test your app's deep link handling mechanism. - * await device.launchApp({url: url}); - */ - launchApp(config: DeviceLanchAppConfig): Promise; - /** - * By default, terminateApp() with no params will terminate the app - * To terminate another app, specify its bundle id - * @param bundle - * @example await device.terminateApp('other.bundle.id'); - */ - terminateApp(bundle?: string): Promise; - /** - * Send application to background by bringing com.apple.springboard to the foreground. - * Combining sendToHome() with launchApp({newInstance: false}) will simulate app coming back from background. - * @example await device.sendToHome(); - * await device.launchApp({newInstance: false}); - */ - sendToHome(): Promise; - /** - * If this is a React Native app, reload the React Native JS bundle. This action is much faster than device.launchApp(), and can be used if you just need to reset your React Native logic. - * @example await device.reloadReactNative() - */ - reloadReactNative(): Promise; - /** - * By default, installApp() with no params will install the app file defined in the current configuration. - * To install another app, specify its path - * @param path - * @example await device.installApp('path/to/other/app'); - */ - installApp(path?: any): Promise; - /** - * By default, uninstallApp() with no params will uninstall the app defined in the current configuration. - * To uninstall another app, specify its bundle id - * @param bundle - * @example await device.installApp('other.bundle.id'); - */ - uninstallApp(bundle?: string): Promise; - /** - * Mock opening the app from URL. sourceApp is an optional parameter to specify source application bundle id. - * @param url - */ - openURL(url: {url: string, sourceApp?: string}): Promise; - /** - * Mock handling of received user notification when app is in foreground. - * @param params - */ - sendUserNotification(...params: any[]): Promise; - /** - * Mock handling of received user activity when app is in foreground. - * @param params - */ - sendUserActivity(...params: any[]): Promise; - /** - * Takes "portrait" or "landscape" and rotates the device to the given orientation. Currently only available in the iOS Simulator. - * @param orientation - */ - setOrientation(orientation: Orientation): Promise; - /** - * Note: setLocation is dependent on fbsimctl. if fbsimctl is not installed, the command will fail, it must be installed. Sets the simulator location to the given latitude and longitude. - * @param lat - * @param lon - * @example await device.setLocation(32.0853, 34.7818); - */ - setLocation(lat: number, lon: number): Promise; - /** - * Disable EarlGrey's network synchronization mechanism on preffered endpoints. Usful if you want to on skip over synchronizing on certain URLs. - * @param urls - * @example await device.setURLBlacklist(['.*127.0.0.1.*']); - */ - setURLBlacklist(urls: string[]): Promise; - /** - * Enable EarlGrey's synchronization mechanism (enabled by default). This is being reset on every new instance of the app. - * @example await device.enableSynchronization(); - */ - enableSynchronization(): Promise; - /** - * Disable EarlGrey's synchronization mechanism (enabled by default) This is being reset on every new instance of the app. - * @example await device.disableSynchronization(); - */ - disableSynchronization(): Promise; - /** - * Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing previously set permissions. - * @example await device.resetContentAndSettings(); - */ - resetContentAndSettings(): Promise; - /** - * Returns the current device, ios or android. - * @example if (device.getPlatform() === 'ios') { - * await expect(loopSwitch).toHaveValue('1'); - * } - */ - getPlatform(): "ios" | "android"; - /** - * Simulate press back button (Android Only) - */ - pressBack(): Promise; - /** - * Simulate shake (iOS Only) - */ - shake(): Promise; - } + namespace Detox { + interface Detox { + /** + * The setup phase happens inside detox.init(). This is the phase where detox reads its configuration, starts a server, loads its expection library and starts a simulator + * @param config + * @param options + * @example const config = require('../package.json').detox; + * + * before(async () => { + * await detox.init(config); + * }); + */ + init(config: any, options?: DetoxInitOptions): Promise; + /** + * Artifacts currently include only logs from the app process before each task + * @param args + */ + beforeEach(...args: any[]): Promise; + /** + * Artifacts currently include only logs from the app process after each task + * @param args + */ + afterEach(...args: any[]): Promise; + /** + * The cleanup phase should happen after all the tests have finished. This is the phase where detox-server shuts down. + * @example after(async () => { + * await detox.cleanup(); + * }); + */ + cleanup(): Promise; + } + interface Device { + /** + * Launch the app + * @param config + * @example // Terminate the app and launch it again. If set to false, the simulator will try to bring app from background, + * // if the app isn't running, it will launch a new instance. default is false + * await device.launchApp({newInstance: true}); + * // Grant or deny runtime permissions for your application. + * await device.launchApp({permissions: {calendar: 'YES'}}); + * // Mock opening the app from URL to test your app's deep link handling mechanism. + * await device.launchApp({url: url}); + */ + launchApp(config: DeviceLanchAppConfig): Promise; + /** + * By default, terminateApp() with no params will terminate the app + * To terminate another app, specify its bundle id + * @param bundle + * @example await device.terminateApp('other.bundle.id'); + */ + terminateApp(bundle?: string): Promise; + /** + * Send application to background by bringing com.apple.springboard to the foreground. + * Combining sendToHome() with launchApp({newInstance: false}) will simulate app coming back from background. + * @example await device.sendToHome(); + * await device.launchApp({newInstance: false}); + */ + sendToHome(): Promise; + /** + * If this is a React Native app, reload the React Native JS bundle. This action is much faster than device.launchApp(), and can be used if you just need to reset your React Native logic. + * @example await device.reloadReactNative() + */ + reloadReactNative(): Promise; + /** + * By default, installApp() with no params will install the app file defined in the current configuration. + * To install another app, specify its path + * @param path + * @example await device.installApp('path/to/other/app'); + */ + installApp(path?: any): Promise; + /** + * By default, uninstallApp() with no params will uninstall the app defined in the current configuration. + * To uninstall another app, specify its bundle id + * @param bundle + * @example await device.installApp('other.bundle.id'); + */ + uninstallApp(bundle?: string): Promise; + /** + * Mock opening the app from URL. sourceApp is an optional parameter to specify source application bundle id. + * @param url + */ + openURL(url: { url: string; sourceApp?: string }): Promise; + /** + * Mock handling of received user notification when app is in foreground. + * @param params + */ + sendUserNotification(...params: any[]): Promise; + /** + * Mock handling of received user activity when app is in foreground. + * @param params + */ + sendUserActivity(...params: any[]): Promise; + /** + * Takes "portrait" or "landscape" and rotates the device to the given orientation. Currently only available in the iOS Simulator. + * @param orientation + */ + setOrientation(orientation: Orientation): Promise; + /** + * Note: setLocation is dependent on fbsimctl. if fbsimctl is not installed, the command will fail, it must be installed. Sets the simulator location to the given latitude and longitude. + * @param lat + * @param lon + * @example await device.setLocation(32.0853, 34.7818); + */ + setLocation(lat: number, lon: number): Promise; + /** + * Disable EarlGrey's network synchronization mechanism on preffered endpoints. Usful if you want to on skip over synchronizing on certain URLs. + * @param urls + * @example await device.setURLBlacklist(['.*127.0.0.1.*']); + */ + setURLBlacklist(urls: string[]): Promise; + /** + * Enable EarlGrey's synchronization mechanism (enabled by default). This is being reset on every new instance of the app. + * @example await device.enableSynchronization(); + */ + enableSynchronization(): Promise; + /** + * Disable EarlGrey's synchronization mechanism (enabled by default) This is being reset on every new instance of the app. + * @example await device.disableSynchronization(); + */ + disableSynchronization(): Promise; + /** + * Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing previously set permissions. + * @example await device.resetContentAndSettings(); + */ + resetContentAndSettings(): Promise; + /** + * Returns the current device, ios or android. + * @example if (device.getPlatform() === 'ios') { + * await expect(loopSwitch).toHaveValue('1'); + * } + */ + getPlatform(): "ios" | "android"; + /** + * Simulate press back button (Android Only) + */ + pressBack(): Promise; + /** + * Simulate shake (iOS Only) + */ + shake(): Promise; + } - type DetoxAny = Element & Actions & WaitFor; + type DetoxAny = Element & Actions & WaitFor; - interface Element { - (by: Matchers): DetoxAny; + interface Element { + (by: Matchers): DetoxAny; - /** - * Choose from multiple elements matching the same matcher using index - * @param index - * @example await element(by.text('Product')).atIndex(2); - */ - atIndex(index: number): DetoxAny; - } - interface Matchers { - (by: Matchers): Matchers; + /** + * Choose from multiple elements matching the same matcher using index + * @param index + * @example await element(by.text('Product')).atIndex(2); + */ + atIndex(index: number): DetoxAny; + } + interface Matchers { + (by: Matchers): Matchers; - /** - * by.id will match an id that is given to the view via testID prop. - * @param id - * @example // In a React Native component add testID like so: - * - * // Then match with by.id: - * await element(by.id('tap_me')); - */ - id(id: string): Matchers; - /** - * Find an element by text, useful for text fields, buttons. - * @param text - * @example await element(by.text('Tap Me')); - */ - text(text: string): Matchers; - /** - * Find an element by accessibilityLabel on iOS, or by contentDescription on Android. - * @param label - * @example await element(by.label('Welcome')); - */ - label(label: string): Matchers; - /** - * Find an element by native view type. - * @param nativeViewType - * @example await element(by.type('RCTImageView')); - */ - type(nativeViewType: string): Matchers; - /** - * Find an element with an accessibility trait. (iOS only) - * @example await element(by.traits(['button'])); - */ - traits(traits: string[]): Matchers; - /** - * Find an element by a matcher with a parent matcher - * @param parentBy - * @example await element(by.id('Grandson883').withAncestor(by.id('Son883'))); - */ - withAncestor(parentBy: Matchers): Matchers; - /** - * Find an element by a matcher with a child matcher - * @param childBy - * @example await element(by.id('Son883').withDescendant(by.id('Grandson883'))); - */ - withDescendant(childBy: Matchers): Matchers; - /** - * Find an element by multiple matchers - * @param by - * @example await element(by.text('Product').and(by.id('product_name')); - */ - and(by: Matchers): Matchers; - } - interface Expect { - (element: Element): Expect; - /** - * Expect the view to be at least 75% visible. - * @example await expect(element(by.id('UniqueId204'))).toBeVisible(); - */ - toBeVisible(): R; - /** - * Expect the view to not be visible. - * @example await expect(element(by.id('UniqueId205'))).toBeNotVisible(); - */ - toBeNotVisible(): R; - /** - * Expect the view to exist in the UI hierarchy. - * @example await expect(element(by.id('UniqueId205'))).toExist(); - */ - toExist(): R; - /** - * Expect the view to not exist in the UI hierarchy. - * @example await expect(element(by.id('RandomJunk959'))).toNotExist(); - */ - toNotExist(): R; - /** - * In React Native apps, expect UI component of type to have text. - * In native iOS apps, expect UI elements of type UIButton, UILabel, UITextField or UITextViewIn to have inputText with text. - * @param text - * @example await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text'); - */ - toHaveText(text: string): R; - /** - * It searches by accessibilityLabel on iOS, or by contentDescription on Android. - * In React Native it can be set for both platforms by defining an accessibilityLabel on the view. - * @param label - * @example await expect(element(by.id('UniqueId204'))).toHaveLabel('Done'); - */ - toHaveLabel(label: string): R; - /** - * In React Native apps, expect UI component to have testID with that id. - * In native iOS apps, expect UI element to have accesibilityIdentifier with that id. - * @param id - * @example await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204'); - */ - toHaveId(id: string): R; - /** - * Expect components like a Switch to have a value ('0' for off, '1' for on). - * @param value - * @example await expect(element(by.id('UniqueId533'))).toHaveValue('0'); - */ - toHaveValue(value: any): R; - } - interface WaitFor { - /** - * This API polls using the given expectation continuously until the expectation is met. Use manual synchronization with waitFor only as a last resort. - * NOTE: Every waitFor call must set a timeout using withTimeout(). Calling waitFor without setting a timeout will do nothing. - * @example await waitFor(element(by.id('UniqueId336'))).toExist().withTimeout(2000); - */ - (element: Element): Expect; - /** - * Waits for the condition to be met until the specified time (millis) have elapsed. - * @param millis number - * @example await waitFor(element(by.id('UniqueId336'))).toExist().withTimeout(2000); - */ - withTimeout(millis: number): Promise; - /** - * Performs the action repeatedly on the element until an expectation is met - * @param by - * @example await waitFor(element(by.text('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down'); - */ - whileElement(by: Matchers): DetoxAny; - } - interface Actions { - /** - * Simulate tap on an element - * @example await element(by.id('tappable')).tap(); - */ - tap(): Promise>; - /** - * Simulate long press on an element - * @example await element(by.id('tappable')).longPress(); - */ - longPress(): Promise>; - /** - * Simulate multiple taps on an element. - * @param times number - * @example await element(by.id('tappable')).multiTap(3); - */ - multiTap(times: number): Promise>; - /** - * Simulate tap at a specific point on an element. - * Note: The point coordinates are relative to the matched element and the element size could changes on different devices or even when changing the device font size. - * @param point - * @example await element(by.id('tappable')).tapAtPoint({ x:5, y:10 }); - */ - tapAtPoint(point: { x: number, y: number }): Promise>; - /** - * Use the builtin keyboard to type text into a text field. - * @param text - * @example await element(by.id('textField')).typeText('passcode'); - */ - typeText(text: string): Promise>; - /** - * Paste text into a text field. - * @param text - * @example await element(by.id('textField')).replaceText('passcode again'); - */ - replaceText(text: string): Promise>; - /** - * Clear text from a text field. - * @example await element(by.id('textField')).clearText(); - */ - clearText(): Promise>; - /** - * - * @param pixels - * @param direction - * @example - * await element(by.id('scrollView')).scroll(100, 'down'); - * await element(by.id('scrollView')).scroll(100, 'up'); - */ - scroll(pixels: number, direction: Direction): Promise>; - /** - * Scroll to edge. - * @param edge - * @example await element(by.id('scrollView')).scrollTo('bottom'); - * await element(by.id('scrollView')).scrollTo('top'); - */ - scrollTo(edge: Direction): Promise>; - /** - * - * @param direction - * @param speed - * @param percentage - * @example await element(by.id('scrollView')).swipe('down'); - * await element(by.id('scrollView')).swipe('down', 'fast'); - * await element(by.id('scrollView')).swipe('down', 'fast', 0.5); - */ - swipe(direction: Direction, speed?: Speed, percentage?: number): Promise>; - /** - * (iOS Only) column - number of datepicker column (starts from 0) value - string value in setted column (must be correct) - * @param column - * @param value - * @example await expect(element(by.type('UIPickerView'))).toBeVisible(); - * await element(by.type('UIPickerView')).setColumnToValue(1,"6"); - * await element(by.type('UIPickerView')).setColumnToValue(2,"34"); - */ - setColumnToValue(column: number, value: string): Promise>; - } + /** + * by.id will match an id that is given to the view via testID prop. + * @param id + * @example // In a React Native component add testID like so: + * + * // Then match with by.id: + * await element(by.id('tap_me')); + */ + id(id: string): Matchers; + /** + * Find an element by text, useful for text fields, buttons. + * @param text + * @example await element(by.text('Tap Me')); + */ + text(text: string): Matchers; + /** + * Find an element by accessibilityLabel on iOS, or by contentDescription on Android. + * @param label + * @example await element(by.label('Welcome')); + */ + label(label: string): Matchers; + /** + * Find an element by native view type. + * @param nativeViewType + * @example await element(by.type('RCTImageView')); + */ + type(nativeViewType: string): Matchers; + /** + * Find an element with an accessibility trait. (iOS only) + * @example await element(by.traits(['button'])); + */ + traits(traits: string[]): Matchers; + /** + * Find an element by a matcher with a parent matcher + * @param parentBy + * @example await element(by.id('Grandson883').withAncestor(by.id('Son883'))); + */ + withAncestor(parentBy: Matchers): Matchers; + /** + * Find an element by a matcher with a child matcher + * @param childBy + * @example await element(by.id('Son883').withDescendant(by.id('Grandson883'))); + */ + withDescendant(childBy: Matchers): Matchers; + /** + * Find an element by multiple matchers + * @param by + * @example await element(by.text('Product').and(by.id('product_name')); + */ + and(by: Matchers): Matchers; + } + interface Expect { + (element: Element): Expect; + /** + * Expect the view to be at least 75% visible. + * @example await expect(element(by.id('UniqueId204'))).toBeVisible(); + */ + toBeVisible(): R; + /** + * Expect the view to not be visible. + * @example await expect(element(by.id('UniqueId205'))).toBeNotVisible(); + */ + toBeNotVisible(): R; + /** + * Expect the view to exist in the UI hierarchy. + * @example await expect(element(by.id('UniqueId205'))).toExist(); + */ + toExist(): R; + /** + * Expect the view to not exist in the UI hierarchy. + * @example await expect(element(by.id('RandomJunk959'))).toNotExist(); + */ + toNotExist(): R; + /** + * In React Native apps, expect UI component of type to have text. + * In native iOS apps, expect UI elements of type UIButton, UILabel, UITextField or UITextViewIn to have inputText with text. + * @param text + * @example await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text'); + */ + toHaveText(text: string): R; + /** + * It searches by accessibilityLabel on iOS, or by contentDescription on Android. + * In React Native it can be set for both platforms by defining an accessibilityLabel on the view. + * @param label + * @example await expect(element(by.id('UniqueId204'))).toHaveLabel('Done'); + */ + toHaveLabel(label: string): R; + /** + * In React Native apps, expect UI component to have testID with that id. + * In native iOS apps, expect UI element to have accesibilityIdentifier with that id. + * @param id + * @example await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204'); + */ + toHaveId(id: string): R; + /** + * Expect components like a Switch to have a value ('0' for off, '1' for on). + * @param value + * @example await expect(element(by.id('UniqueId533'))).toHaveValue('0'); + */ + toHaveValue(value: any): R; + } + interface WaitFor { + /** + * This API polls using the given expectation continuously until the expectation is met. Use manual synchronization with waitFor only as a last resort. + * NOTE: Every waitFor call must set a timeout using withTimeout(). Calling waitFor without setting a timeout will do nothing. + * @example await waitFor(element(by.id('UniqueId336'))).toExist().withTimeout(2000); + */ + (element: Element): Expect; + /** + * Waits for the condition to be met until the specified time (millis) have elapsed. + * @param millis number + * @example await waitFor(element(by.id('UniqueId336'))).toExist().withTimeout(2000); + */ + withTimeout(millis: number): Promise; + /** + * Performs the action repeatedly on the element until an expectation is met + * @param by + * @example await waitFor(element(by.text('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down'); + */ + whileElement(by: Matchers): DetoxAny; + } + interface Actions { + /** + * Simulate tap on an element + * @example await element(by.id('tappable')).tap(); + */ + tap(): Promise>; + /** + * Simulate long press on an element + * @example await element(by.id('tappable')).longPress(); + */ + longPress(): Promise>; + /** + * Simulate multiple taps on an element. + * @param times number + * @example await element(by.id('tappable')).multiTap(3); + */ + multiTap(times: number): Promise>; + /** + * Simulate tap at a specific point on an element. + * Note: The point coordinates are relative to the matched element and the element size could changes on different devices or even when changing the device font size. + * @param point + * @example await element(by.id('tappable')).tapAtPoint({ x:5, y:10 }); + */ + tapAtPoint(point: { x: number; y: number }): Promise>; + /** + * Use the builtin keyboard to type text into a text field. + * @param text + * @example await element(by.id('textField')).typeText('passcode'); + */ + typeText(text: string): Promise>; + /** + * Paste text into a text field. + * @param text + * @example await element(by.id('textField')).replaceText('passcode again'); + */ + replaceText(text: string): Promise>; + /** + * Clear text from a text field. + * @example await element(by.id('textField')).clearText(); + */ + clearText(): Promise>; + /** + * + * @param pixels + * @param direction + * @example + * await element(by.id('scrollView')).scroll(100, 'down'); + * await element(by.id('scrollView')).scroll(100, 'up'); + */ + scroll(pixels: number, direction: Direction): Promise>; + /** + * Scroll to edge. + * @param edge + * @example await element(by.id('scrollView')).scrollTo('bottom'); + * await element(by.id('scrollView')).scrollTo('top'); + */ + scrollTo(edge: Direction): Promise>; + /** + * + * @param direction + * @param speed + * @param percentage + * @example await element(by.id('scrollView')).swipe('down'); + * await element(by.id('scrollView')).swipe('down', 'fast'); + * await element(by.id('scrollView')).swipe('down', 'fast', 0.5); + */ + swipe( + direction: Direction, + speed?: Speed, + percentage?: number + ): Promise>; + /** + * (iOS Only) column - number of datepicker column (starts from 0) value - string value in setted column (must be correct) + * @param column + * @param value + * @example await expect(element(by.type('UIPickerView'))).toBeVisible(); + * await element(by.type('UIPickerView')).setColumnToValue(1,"6"); + * await element(by.type('UIPickerView')).setColumnToValue(2,"34"); + */ + setColumnToValue( + column: number, + value: string + ): Promise>; + } - type Direction = "left" | "right" | "top" | "bottom" | "up" | "down"; - type Orientation = "portrait" | "landscape"; - type Speed = "fast" | "slow"; + type Direction = "left" | "right" | "top" | "bottom" | "up" | "down"; + type Orientation = "portrait" | "landscape"; + type Speed = "fast" | "slow"; - interface DetoxInitOptions { - /** - * Detox exports device, expect, element, by and waitFor as globals by default, if you want to control their initialization manually, set init detox with initGlobals set to false. - * This is useful when during E2E tests you also need to run regular expectations in node. jest Expect for instance, will not be overriden by Detox when this option is used. - */ - initGlobals?: boolean; - /** - * By default await detox.init(config); will launch the installed app. If you wish to control when your app is launched, add {launchApp: false} param to your init. - */ - launchApp?: boolean; - } + interface DetoxInitOptions { + /** + * Detox exports device, expect, element, by and waitFor as globals by default, if you want to control their initialization manually, set init detox with initGlobals set to false. + * This is useful when during E2E tests you also need to run regular expectations in node. jest Expect for instance, will not be overriden by Detox when this option is used. + */ + initGlobals?: boolean; + /** + * By default await detox.init(config); will launch the installed app. If you wish to control when your app is launched, add {launchApp: false} param to your init. + */ + launchApp?: boolean; + } - interface DeviceLanchAppConfig { - /** - * Restart the app - * Terminate the app and launch it again. If set to false, the simulator will try to bring app from background, if the app isn't running, it will launch a new instance. default is false - */ - newInstance?: boolean; - /** - * Set runtime permissions - * Grant or deny runtime permissions for your application. - */ - permissions?: any; - /** - * Launch from URL - * Mock opening the app from URL to test your app's deep link handling mechanism. - */ - url?: any; - /** - * Launch with user notifications - */ - userNotification?: any; - /** - * Launch with user activity - */ - userActivity?: any; - /** - * Launch into a fresh installation - * A flag that enables relaunching into a fresh installation of the app (it will uninstall and install the binary again), default is false. - */ - delete?: boolean; - /** - * Detox can start the app with additional launch arguments - * The added launchArgs will be passed through the launch command to the device and be accessible via [[NSProcessInfo processInfo] arguments] - */ - launchArgs?: any; + interface DeviceLanchAppConfig { + /** + * Restart the app + * Terminate the app and launch it again. If set to false, the simulator will try to bring app from background, if the app isn't running, it will launch a new instance. default is false + */ + newInstance?: boolean; + /** + * Set runtime permissions + * Grant or deny runtime permissions for your application. + */ + permissions?: any; + /** + * Launch from URL + * Mock opening the app from URL to test your app's deep link handling mechanism. + */ + url?: any; + /** + * Launch with user notifications + */ + userNotification?: any; + /** + * Launch with user activity + */ + userActivity?: any; + /** + * Launch into a fresh installation + * A flag that enables relaunching into a fresh installation of the app (it will uninstall and install the binary again), default is false. + */ + delete?: boolean; + /** + * Detox can start the app with additional launch arguments + * The added launchArgs will be passed through the launch command to the device and be accessible via [[NSProcessInfo processInfo] arguments] + */ + launchArgs?: any; + } } } + +export { by, detox, device, element, expect, waitFor }; From 700298f03a177fd488245bd0d0a77212085cb0d3 Mon Sep 17 00:00:00 2001 From: Jeff Held Date: Thu, 8 Nov 2018 17:11:01 -0600 Subject: [PATCH 005/792] detox: add jest adapter definitions --- types/detox/runners/jest/adapters/index.d.ts | 9 +++++++ types/detox/tests/detox-jest-setup-tests.ts | 28 ++++++++++++++++++++ types/detox/tsconfig.json | 4 ++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 types/detox/runners/jest/adapters/index.d.ts create mode 100644 types/detox/tests/detox-jest-setup-tests.ts diff --git a/types/detox/runners/jest/adapters/index.d.ts b/types/detox/runners/jest/adapters/index.d.ts new file mode 100644 index 0000000000..ca195ae744 --- /dev/null +++ b/types/detox/runners/jest/adapters/index.d.ts @@ -0,0 +1,9 @@ +interface DetoxJestAdapter { + detox: Detox.Detox; + beforeEach: () => Promise; + afterAll: () => Promise; +} + +declare const adapter: DetoxJestAdapter; + +export default adapter; diff --git a/types/detox/tests/detox-jest-setup-tests.ts b/types/detox/tests/detox-jest-setup-tests.ts new file mode 100644 index 0000000000..002b5605bb --- /dev/null +++ b/types/detox/tests/detox-jest-setup-tests.ts @@ -0,0 +1,28 @@ +declare var beforeAll: (callback: () => void) => void; +declare var beforeEach: (callback: () => void) => void; +declare var afterAll: (callback: () => void) => void; + +import adapter from "detox/runners/jest/adapters"; + +// Normally the Detox configuration from the project's package.json like so: +// const config = require("./package.json").detox; +declare const config: any; + +beforeAll(async () => { + await detox.init(config); + + const initOptions: Detox.DetoxInitOptions = { + initGlobals: false, + launchApp: false, + }; + await detox.init(config, initOptions); +}); + +beforeEach(async () => { + await adapter.beforeEach(); +}); + +afterAll(async () => { + await adapter.afterAll(); + await detox.cleanup(); +}); diff --git a/types/detox/tsconfig.json b/types/detox/tsconfig.json index 3eb7524be2..9440443222 100644 --- a/types/detox/tsconfig.json +++ b/types/detox/tsconfig.json @@ -15,7 +15,9 @@ }, "files": [ "index.d.ts", + "runners/jest/adapters/index.d.ts", "tests/detox-globals-tests.ts", - "tests/detox-import-modules-tests.ts" + "tests/detox-import-modules-tests.ts", + "tests/detox-jest-setup-tests.ts" ] } From f627c9caf605e2c6bd920b79d87b17fd34a21c0b Mon Sep 17 00:00:00 2001 From: Jeff Held Date: Thu, 8 Nov 2018 17:11:13 -0600 Subject: [PATCH 006/792] detox: add mocha adapter definitions --- types/detox/runners/mocha/adapters/index.d.ts | 9 ++++++ .../detox-global-tests.ts} | 0 .../{tests => test}/detox-jest-setup-tests.ts | 0 types/detox/test/detox-mocha-setup-tests.ts | 32 +++++++++++++++++++ .../detox-module-tests.ts} | 0 types/detox/tsconfig.json | 8 +++-- 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 types/detox/runners/mocha/adapters/index.d.ts rename types/detox/{tests/detox-globals-tests.ts => test/detox-global-tests.ts} (100%) rename types/detox/{tests => test}/detox-jest-setup-tests.ts (100%) create mode 100644 types/detox/test/detox-mocha-setup-tests.ts rename types/detox/{tests/detox-import-modules-tests.ts => test/detox-module-tests.ts} (100%) diff --git a/types/detox/runners/mocha/adapters/index.d.ts b/types/detox/runners/mocha/adapters/index.d.ts new file mode 100644 index 0000000000..8e13b3bc01 --- /dev/null +++ b/types/detox/runners/mocha/adapters/index.d.ts @@ -0,0 +1,9 @@ +interface DetoxMochaAdapter { + detox: Detox.Detox; + beforeEach: (context: any) => Promise; + afterEach: (context: any) => Promise; +} + +declare const adapter: DetoxMochaAdapter; + +export default adapter; diff --git a/types/detox/tests/detox-globals-tests.ts b/types/detox/test/detox-global-tests.ts similarity index 100% rename from types/detox/tests/detox-globals-tests.ts rename to types/detox/test/detox-global-tests.ts diff --git a/types/detox/tests/detox-jest-setup-tests.ts b/types/detox/test/detox-jest-setup-tests.ts similarity index 100% rename from types/detox/tests/detox-jest-setup-tests.ts rename to types/detox/test/detox-jest-setup-tests.ts diff --git a/types/detox/test/detox-mocha-setup-tests.ts b/types/detox/test/detox-mocha-setup-tests.ts new file mode 100644 index 0000000000..3f502d1391 --- /dev/null +++ b/types/detox/test/detox-mocha-setup-tests.ts @@ -0,0 +1,32 @@ +// tslint:disable:only-arrow-functions + +declare var before: (callback: () => void) => void; +declare var beforeEach: (callback: () => void) => void; +declare var after: (callback: () => void) => void; +declare var afterEach: (callback: () => void) => void; + +import adapter from "detox/runners/mocha/adapters"; + +// Normally the Detox configuration from the project's package.json like so: +// const config = require("./package.json").detox; +declare const config: any; + +// Normally, the beforeEach and afterEach function should take `this` as its argument, +// but `this` cannot be used since it doesn't have a type signature (and therefore always implicltly any) +declare const context: any; + +before(async function() { + await detox.init(config); +}); + +beforeEach(async function() { + await adapter.beforeEach(context); +}); + +afterEach(async function() { + await adapter.afterEach(context); +}); + +after(async function() { + await detox.cleanup(); +}); diff --git a/types/detox/tests/detox-import-modules-tests.ts b/types/detox/test/detox-module-tests.ts similarity index 100% rename from types/detox/tests/detox-import-modules-tests.ts rename to types/detox/test/detox-module-tests.ts diff --git a/types/detox/tsconfig.json b/types/detox/tsconfig.json index 9440443222..7be4d3bb9e 100644 --- a/types/detox/tsconfig.json +++ b/types/detox/tsconfig.json @@ -16,8 +16,10 @@ "files": [ "index.d.ts", "runners/jest/adapters/index.d.ts", - "tests/detox-globals-tests.ts", - "tests/detox-import-modules-tests.ts", - "tests/detox-jest-setup-tests.ts" + "runners/mocha/adapters/index.d.ts", + "test/detox-global-tests.ts", + "test/detox-module-tests.ts", + "test/detox-jest-setup-tests.ts", + "test/detox-mocha-setup-tests.ts" ] } From 53db0897816810df904fbbbbda46fef65a1c1e1a Mon Sep 17 00:00:00 2001 From: Yann Normand Date: Fri, 9 Nov 2018 15:14:19 +1000 Subject: [PATCH 007/792] add a new generic for resource type --- types/react-big-calendar/index.d.ts | 28 +++++++-------- .../react-big-calendar-tests.tsx | 35 ++++++++++++++++--- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/types/react-big-calendar/index.d.ts b/types/react-big-calendar/index.d.ts index bbfd7047ec..eba901bfc9 100644 --- a/types/react-big-calendar/index.d.ts +++ b/types/react-big-calendar/index.d.ts @@ -171,19 +171,19 @@ export class DateLocalizer { format(value: FormatInput, format: string, culture: Culture): string; } -export interface BigCalendarProps extends React.Props> { +export interface BigCalendarProps extends React.Props> { localizer: DateLocalizer; date?: stringOrDate; now?: Date; view?: View; - events?: T[]; + events?: TEvent[]; onNavigate?: (newDate: Date, action: Navigate) => void; onView?: (view: View) => void; onDrillDown?: (date: Date, view: View) => void; onSelectSlot?: (slotInfo: { start: stringOrDate, end: stringOrDate, slots: Date[] | string[], action: 'select' | 'click' | 'doubleClick' }) => void; - onDoubleClickEvent?: (event: T, e: React.SyntheticEvent) => void; - onSelectEvent?: (event: T, e: React.SyntheticEvent) => void; + onDoubleClickEvent?: (event: TEvent, e: React.SyntheticEvent) => void; + onSelectEvent?: (event: TEvent, e: React.SyntheticEvent) => void; onSelecting?: (range: { start: stringOrDate, end: stringOrDate }) => boolean | undefined | null; selected?: any; views?: View[] | { @@ -202,7 +202,7 @@ export interface BigCalendarProps extends React.Props { className?: string, style?: React.CSSProperties }; + eventPropGetter?: (event: TEvent, start: stringOrDate, end: stringOrDate, isSelected: boolean) => { className?: string, style?: React.CSSProperties }; slotPropGetter?: (date: Date) => { className?: string, style?: object }; dayPropGetter?: (date: Date) => { className?: string, style?: object }; showMultiDayTimes?: boolean; @@ -213,14 +213,14 @@ export interface BigCalendarProps extends React.Props string); - allDayAccessor?: keyof T | ((event: T) => boolean); - startAccessor?: keyof T | ((event: T) => Date); - endAccessor?: keyof T | ((event: T) => Date); - resourceAccessor?: keyof T | ((event: T) => any); - resources?: any[]; - resourceIdAccessor?: keyof T | ((event: T) => any); - resourceTitleAccessor?: keyof T | ((event: T) => string); + titleAccessor?: keyof TEvent | ((event: TEvent) => string); + allDayAccessor?: keyof TEvent | ((event: TEvent) => boolean); + startAccessor?: keyof TEvent | ((event: TEvent) => Date); + endAccessor?: keyof TEvent | ((event: TEvent) => Date); + resourceAccessor?: keyof TEvent | ((event: TEvent) => any); + resources?: TResource[]; + resourceIdAccessor?: keyof TResource | ((resource: TResource) => any); + resourceTitleAccessor?: keyof TResource | ((resource: TResource) => string); defaultView?: View; defaultDate?: Date; className?: string; @@ -237,7 +237,7 @@ export interface MoveOptions { today: Date; } -export default class BigCalendar extends React.Component> { +export default class BigCalendar extends React.Component> { components: { dateCellWrapper: React.ComponentType, dayWrapper: React.ComponentType, diff --git a/types/react-big-calendar/react-big-calendar-tests.tsx b/types/react-big-calendar/react-big-calendar-tests.tsx index e1b561901e..e50858c546 100644 --- a/types/react-big-calendar/react-big-calendar-tests.tsx +++ b/types/react-big-calendar/react-big-calendar-tests.tsx @@ -17,13 +17,25 @@ class CalendarEvent { start: Date; end: Date; desc: string; + resourceId?: string; - constructor(_title: string, _start: Date, _end: Date, _allDay?: boolean, _desc?: string) { + constructor(_title: string, _start: Date, _end: Date, _allDay?: boolean, _desc?: string, _resourceId?: string) { this.title = _title; this.allDay = _allDay || false; this.start = _start; this.end = _end; this.desc = _desc || ''; + this.resourceId = _resourceId; + } +} + +class CalendarResource { + title: string; + id: string; + + constructor(id: string, title: string) { + this.id = id; + this.title = title; } } @@ -51,10 +63,10 @@ class CalendarEvent { { // Full API Example Test - based on API Documentation // http://intljusticemission.github.io/react-big-calendar/examples/index.html#api - class FullAPIExample extends React.Component> { + class FullAPIExample extends React.Component> { render() { return ( - {...this.props} date={new Date()} view={'day'} @@ -81,9 +93,9 @@ class CalendarEvent { rtl={true} eventPropGetter={(event, start, end, isSelected) => ({ className: 'some-class' })} titleAccessor={'title'} - allDayAccessor={(event: any) => !!event.allDay} + allDayAccessor={(event: CalendarEvent) => !!event.allDay} startAccessor={'start'} - endAccessor={(event: any) => event.end || event.start} + endAccessor={(event: CalendarEvent) => event.end || event.start} min={new Date()} max={new Date()} scrollToTime={new Date()} @@ -106,6 +118,10 @@ class CalendarEvent { dayPropGetter={customDayPropGetter} slotPropGetter={customSlotPropGetter} defaultDate={new Date()} + resources={getResources()} + resourceAccessor={event => event.resourceId} + resourceIdAccessor={resource => resource.id} + resourceTitleAccessor={resource => resource.title} /> ); } @@ -130,10 +146,19 @@ function getEvents(): CalendarEvent[] { new CalendarEvent('Happy Hour', new Date(2015, 3, 12, 17, 0, 0, 0), new Date(2015, 3, 12, 17, 30, 0, 0), undefined, 'Most important meal of the day'), new CalendarEvent('Dinner', new Date(2015, 3, 12, 20, 0, 0, 0), new Date(2015, 3, 12, 21, 0, 0, 0)), new CalendarEvent('Birthday Party', new Date(2015, 3, 13, 7, 0, 0), new Date(2015, 3, 13, 10, 30, 0)), + new CalendarEvent('Alice\'s break', new Date(2015, 3, 14, 20, 0, 0, 0), new Date(2015, 3, 14, 21, 0, 0, 0), undefined, undefined, "alice"), + new CalendarEvent('Bob\'s break', new Date(2015, 3, 15, 7, 0, 0), new Date(2015, 3, 15, 10, 30, 0), undefined, undefined, "bob"), ]; return events; } +function getResources(): CalendarResource[] { + return [ + new CalendarResource('alice', 'Alice'), + new CalendarResource('bob', 'Bob') + ]; +} + class EventAgenda extends React.Component { render() { // const { label } = this.props; From fe1169f35d5b0b9f577674f6c1ea0e34f58871af Mon Sep 17 00:00:00 2001 From: Yann Normand Date: Fri, 9 Nov 2018 16:30:58 +1000 Subject: [PATCH 008/792] upgrade to TypeScript Version 2.9 --- types/react-big-calendar/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-big-calendar/index.d.ts b/types/react-big-calendar/index.d.ts index eba901bfc9..e7faf76ff4 100644 --- a/types/react-big-calendar/index.d.ts +++ b/types/react-big-calendar/index.d.ts @@ -6,7 +6,7 @@ // Sebastian Silbermann // Paul Potsides // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 2.9 import { Validator } from 'prop-types'; import * as React from 'react'; From 6ffd9f2bc60165a597b34cc1ea55ee823fccc851 Mon Sep 17 00:00:00 2001 From: Yann Normand Date: Fri, 9 Nov 2018 16:33:24 +1000 Subject: [PATCH 009/792] fix onNavigate function --- types/react-big-calendar/index.d.ts | 2 +- types/react-big-calendar/react-big-calendar-tests.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-big-calendar/index.d.ts b/types/react-big-calendar/index.d.ts index e7faf76ff4..0e7da106c2 100644 --- a/types/react-big-calendar/index.d.ts +++ b/types/react-big-calendar/index.d.ts @@ -178,7 +178,7 @@ export interface BigCalendarProps void; + onNavigate?: (newDate: Date, view: View, action: Navigate) => void; onView?: (view: View) => void; onDrillDown?: (date: Date, view: View) => void; onSelectSlot?: (slotInfo: { start: stringOrDate, end: stringOrDate, slots: Date[] | string[], action: 'select' | 'click' | 'doubleClick' }) => void; diff --git a/types/react-big-calendar/react-big-calendar-tests.tsx b/types/react-big-calendar/react-big-calendar-tests.tsx index e50858c546..4b80e8a72c 100644 --- a/types/react-big-calendar/react-big-calendar-tests.tsx +++ b/types/react-big-calendar/react-big-calendar-tests.tsx @@ -71,7 +71,7 @@ class CalendarResource { date={new Date()} view={'day'} events={getEvents()} - onNavigate={(newDate: Date, action: Navigate) => { }} + onNavigate={(newDate: Date, view: View, action: Navigate) => { }} onView={(view: View) => { }} onSelectSlot={(slotInfo) => { const start = slotInfo.start; From f18851bea8e67645232633c8c88321add78a1822 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Fri, 16 Nov 2018 10:35:29 -0800 Subject: [PATCH 010/792] Add onBeforeInput form events. --- types/react/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 332d3ac640..2a1c7baf7b 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -808,6 +808,8 @@ declare namespace React { // Form Events onChange?: FormEventHandler; onChangeCapture?: FormEventHandler; + onBeforeInput?: FormEventHandler; + onBeforeInputCapture?: FormEventHandler; onInput?: FormEventHandler; onInputCapture?: FormEventHandler; onReset?: FormEventHandler; From 7364d8937f28c0460ff0eefd3ee1a3e7bd6393e3 Mon Sep 17 00:00:00 2001 From: HokieGeek Date: Fri, 16 Nov 2018 15:30:20 -0500 Subject: [PATCH 011/792] @types/lunr: Updated Builder functions to add new optional arguments --- types/lunr/index.d.ts | 17 +++++++++++++---- types/lunr/lunr-tests.ts | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/types/lunr/index.d.ts b/types/lunr/index.d.ts index da87ae95d8..415c7c1d8f 100644 --- a/types/lunr/index.d.ts +++ b/types/lunr/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for lunr.js 2.1 +// Type definitions for lunr.js 2.3 // Project: https://github.com/olivernn/lunr.js -// Definitions by: Sean Tan +// Definitions by: Sean Tan , AndrΓ©s PΓ©rez // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -127,9 +127,14 @@ declare namespace lunr { * All fields should be added before adding documents to the index. Adding fields after * a document has been indexed will have no effect on already indexed documents. * + * Fields can be boosted at build time. This allows terms within that field to have more + * importance when ranking search results. Use a field boost to specify that matches + * within one field are more important than other fields. + * * @param field - The name of a field to index in all documents. + * @param attributes - Optional attributes associated with this field. */ - field(field: string): void; + field(field: string, attributes?: object): void; /** * A parameter to tune the amount of field length normalisation that is applied when @@ -160,9 +165,13 @@ declare namespace lunr { * it should have all fields defined for indexing, though null or undefined values will not * cause errors. * + * Entire documents can be boosted at build time. Applying a boost to a document indicates that + * this document should rank higher in search results than other documents. + * * @param doc - The document to add to the index. + * @param attributes - Optional attributes associated with this document. */ - add(doc: object): void; + add(doc: object, attributes?: object): void; /** * Builds the index, creating an instance of lunr.Index. diff --git a/types/lunr/lunr-tests.ts b/types/lunr/lunr-tests.ts index ade45cae64..a14fd1947f 100644 --- a/types/lunr/lunr-tests.ts +++ b/types/lunr/lunr-tests.ts @@ -4,11 +4,18 @@ function basic_test() { const index = lunr(function() { this.field("title"); this.field("body"); + this.field("content", { + boost: 2, + extractor: (doc: object) => "oof" + }); this.ref("id"); this.add({ id: 1, title: "Foo", body: "Foo foo foo!" + }, + { + boost: 2 }); this.add({ id: 2, From a7e72529b207c1529dd2ad7707f154ac0e359b86 Mon Sep 17 00:00:00 2001 From: robbywashere Date: Fri, 16 Nov 2018 22:16:01 -0500 Subject: [PATCH 012/792] Update to types/recompose package withStateHandler to give stateUpdaters typed arguments rather than --- types/recompose/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/recompose/index.d.ts b/types/recompose/index.d.ts index 6f61888954..edb8ef9415 100644 --- a/types/recompose/index.d.ts +++ b/types/recompose/index.d.ts @@ -151,7 +151,7 @@ declare module 'recompose' { [updaterName: string]: StateHandler; }; type StateUpdaters = { - [updaterName in keyof TUpdaters]: (state: TState, props: TOutter) => StateHandler; + [updaterName in keyof TUpdaters]: (state: TState, props: TOutter) => TUpdaters[updaterName]; }; export function withStateHandlers, TOutter = {}>( createProps: TState | mapper, From 8e0be6712ba2c19b495ffc32b8ffb37ff8eb21f6 Mon Sep 17 00:00:00 2001 From: denis Date: Sat, 17 Nov 2018 11:05:38 +0100 Subject: [PATCH 013/792] Fix no-angle-bracket-type-assertion --- types/d3-brush/d3-brush-tests.ts | 2 +- types/d3-drag/d3-drag-tests.ts | 6 +++--- types/d3-selection/d3-selection-tests.ts | 2 +- types/d3-selection/tslint.json | 1 - types/d3-zoom/d3-zoom-tests.ts | 8 ++++---- types/d3-zoom/tslint.json | 1 - types/d3kit/d3kit-tests.ts | 4 ++-- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/types/d3-brush/d3-brush-tests.ts b/types/d3-brush/d3-brush-tests.ts index dc2c9a0dc8..c5a287b562 100644 --- a/types/d3-brush/d3-brush-tests.ts +++ b/types/d3-brush/d3-brush-tests.ts @@ -48,7 +48,7 @@ brush = brush.extent(function(d, i, group) { // chainable brush = brush.filter(function(d, i, group) { // Cast d3 event to D3ZoomEvent to be used in filter logic - const e = > event; + const e = event as d3Brush.D3BrushEvent; console.log('Owner SVG Element of svg group: ', this.ownerSVGElement); // this is of type SVGGElement return e.sourceEvent.type !== 'zoom' || !d.filterZoomEvent; // datum type is BrushDatum (as propagated to SVGGElement with brush event attached) diff --git a/types/d3-drag/d3-drag-tests.ts b/types/d3-drag/d3-drag-tests.ts index cf5428e7e2..5e376c003b 100644 --- a/types/d3-drag/d3-drag-tests.ts +++ b/types/d3-drag/d3-drag-tests.ts @@ -134,7 +134,7 @@ touchableFn = circleDrag.touchable(); circleCustomDrag.subject(function(d, i, g) { // Cast event type for completeness, otherwise event is of type any. - const e = > event; + const e = event as d3Drag.D3DragEvent; const that: SVGCircleElement = this; const datum: CircleDatum = d; const index: number = i; @@ -163,14 +163,14 @@ subjectAccessor = circleCustomDrag.subject(); function dragstarted(this: SVGCircleElement, d: CircleDatum) { // cast d3 event to drag event. Otherwise, d3 event is currently defined as type 'any' - const e = > event; + const e = event as d3Drag.D3DragEvent; e.sourceEvent.stopPropagation(); select(this).classed('dragging', true); } function dragged(this: SVGCircleElement, d: CircleDatum) { // cast d3 event to drag event. Otherwise, d3 event is currently defined as type 'any' - const e = > event; + const e = event as d3Drag.D3DragEvent; select(this).attr('cx', d.x = e.x).attr('cy', d.y = e.y); } diff --git a/types/d3-selection/d3-selection-tests.ts b/types/d3-selection/d3-selection-tests.ts index bafc1aeb11..092e8bfa5a 100644 --- a/types/d3-selection/d3-selection-tests.ts +++ b/types/d3-selection/d3-selection-tests.ts @@ -1060,7 +1060,7 @@ interface SuccessEvent { const successEvent = { type: 'wonEuro2016', team: 'Island' }; function customListener(this: HTMLBodyElement | null, finalOpponent: string): string { - const e = d3Selection.event; + const e = d3Selection.event as SuccessEvent; return `${e.team} defeated ${finalOpponent} in the EURO 2016 Cup. Who would have thought!!!`; } diff --git a/types/d3-selection/tslint.json b/types/d3-selection/tslint.json index c89636b4b7..26ee29cf50 100644 --- a/types/d3-selection/tslint.json +++ b/types/d3-selection/tslint.json @@ -2,7 +2,6 @@ "extends": "dtslint/dt.json", "rules": { // TODO - "no-angle-bracket-type-assertion": false, "no-this-assignment": false, "unified-signatures": false, "no-unnecessary-generics": false diff --git a/types/d3-zoom/d3-zoom-tests.ts b/types/d3-zoom/d3-zoom-tests.ts index 19a16930d6..c758e83448 100644 --- a/types/d3-zoom/d3-zoom-tests.ts +++ b/types/d3-zoom/d3-zoom-tests.ts @@ -91,7 +91,7 @@ interface GroupDatum { function zoomedCanvas(this: HTMLCanvasElement, d: CanvasDatum) { // Cast d3 event to D3ZoomEvent to be used in zoom event handler - const e = > event; + const e = event as d3Zoom.D3ZoomEvent; if (context) { context.save(); context.clearRect(0, 0, this.width, this.height); // this element @@ -112,7 +112,7 @@ canvasZoom = d3Zoom.zoom() function zoomedSVGOverlay(this: SVGRectElement) { // Cast d3 event to D3ZoomEvent to be used in zoom event handler - const e = > event; + const e = event as d3Zoom.D3ZoomEvent; g.attr('transform', e.transform.toString()); } @@ -146,7 +146,7 @@ constraintFn = svgZoom.constrain(); // chainable svgZoom = svgZoom.filter(function(d, i, group) { // Cast d3 event to D3ZoomEvent to be used in filter logic - const e = > event; + const e = event as d3Zoom.D3ZoomEvent; console.log('Overlay Rectangle width: ', this.width.baseVal.value); // this typing is SVGRectElement return e.sourceEvent.type !== 'brush' || !d.filterBrushEvent; // datum type is SVGDatum (as propagated to SVGRectElement with zoom event attached) @@ -178,7 +178,7 @@ touchableFn = svgZoom.touchable(); // chainable svgZoom = svgZoom.wheelDelta(function(d, i, group) { // Cast d3 event to D3ZoomEvent to be used in filter logic - const e = event; + const e = event as WheelEvent; const that: SVGRectElement = this; const datum: SVGDatum = d; const index: number = i; diff --git a/types/d3-zoom/tslint.json b/types/d3-zoom/tslint.json index c89636b4b7..26ee29cf50 100644 --- a/types/d3-zoom/tslint.json +++ b/types/d3-zoom/tslint.json @@ -2,7 +2,6 @@ "extends": "dtslint/dt.json", "rules": { // TODO - "no-angle-bracket-type-assertion": false, "no-this-assignment": false, "unified-signatures": false, "no-unnecessary-generics": false diff --git a/types/d3kit/d3kit-tests.ts b/types/d3kit/d3kit-tests.ts index ec3b2de1ce..705b9fcc59 100644 --- a/types/d3kit/d3kit-tests.ts +++ b/types/d3kit/d3kit-tests.ts @@ -304,7 +304,7 @@ function test_svg_chart() { * Test plate functions */ plate = new d3kit.SvgPlate(); - plate = chart.addPlate('a-plate', plate, true); // with doNotAppend + plate = chart.addPlate('a-plate', plate, true) as d3kit.SvgPlate; // with doNotAppend chart = chart.addPlate('a-plate', plate); // without doNotAppend chart = chart.removePlate('a-plate'); @@ -381,7 +381,7 @@ function test_hybrid_chart() { * Test plate functions */ plate = new d3kit.SvgPlate(); - plate = chart.addPlate('a-plate', plate, true); // with doNotAppend + plate = chart.addPlate('a-plate', plate, true) as d3kit.SvgPlate; // with doNotAppend chart = chart.addPlate('a-plate', plate); // without doNotAppend chart = chart.removePlate('a-plate'); From 55f32e23822c29c4fb3c46bba5357f8585a2a0f1 Mon Sep 17 00:00:00 2001 From: Rhys van der Waerden Date: Mon, 19 Nov 2018 10:59:20 +1100 Subject: [PATCH 014/792] Remove zopfli options https://github.com/webpack-contrib/compression-webpack-plugin/pull/65 --- types/compression-webpack-plugin/index.d.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/types/compression-webpack-plugin/index.d.ts b/types/compression-webpack-plugin/index.d.ts index a7b38383ef..b0416ca8b0 100644 --- a/types/compression-webpack-plugin/index.d.ts +++ b/types/compression-webpack-plugin/index.d.ts @@ -22,14 +22,6 @@ declare namespace CompressionPlugin { threshold?: number; minRatio?: number; - // zopfli options - verbose?: boolean; - verbose_more?: boolean; - numiterations?: number; - blocksplitting?: boolean; - blocksplittinglast?: boolean; - blocksplittingmax?: number; - // zlib options level?: number; flush?: number; From ceee1391c7e05e2c46eaef0deedfb8febe3ba432 Mon Sep 17 00:00:00 2001 From: Rhys van der Waerden Date: Mon, 19 Nov 2018 11:51:13 +1100 Subject: [PATCH 015/792] compression-webpack-plugin: Support custom algorithm Had to bump the TypeScript version to detect correct option type based on `algorithm` argument. --- .../compression-webpack-plugin-tests.ts | 53 ++++++++++++++++++- types/compression-webpack-plugin/index.d.ts | 37 ++++++++----- 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts b/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts index 423ca4cea7..e162a6bcb2 100644 --- a/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts +++ b/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts @@ -1,7 +1,9 @@ import { Configuration } from 'webpack'; import CompressionPlugin = require('compression-webpack-plugin'); -const c: Configuration = { +new CompressionPlugin(); + +const config: Configuration = { plugins: [ new CompressionPlugin({ asset: "[path].gz[query]", @@ -13,3 +15,52 @@ const c: Configuration = { }) ] }; + +const configDefaultAlgo = new CompressionPlugin({ + compressionOptions: { level: 7 } +}); + +const zlib: Configuration = { + plugins: [ + new CompressionPlugin({ + algorithm: "deflate", + compressionOptions: { + flush: 5, + windowBits: 20, + level: 7 + } + }) + ] +}; + +const badZlib: Configuration = { + plugins: [ + // $ExpectError + new CompressionPlugin({ + algorithm: "deflate", + compressionOptions: 5 + }) + ] +}; + +function customAlgorithm(input: string, options: number, callback: (err: Error, result: Buffer) => void) { +} + +const custom: Configuration = { + plugins: [ + new CompressionPlugin({ + algorithm: customAlgorithm, + compressionOptions: 5 + }) + ] +}; + +const badCustom: Configuration = { + plugins: [ + // $ExpectError + new CompressionPlugin({ + algorithm: customAlgorithm, + compressionOptions: { flush: 5 } + }) + ] +}; diff --git a/types/compression-webpack-plugin/index.d.ts b/types/compression-webpack-plugin/index.d.ts index b0416ca8b0..9c66248776 100644 --- a/types/compression-webpack-plugin/index.d.ts +++ b/types/compression-webpack-plugin/index.d.ts @@ -2,33 +2,42 @@ // Project: https://github.com/webpack-contrib/compression-webpack-plugin // Definitions by: Anton Kandybo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.4 import { Plugin } from 'webpack'; +import { ZlibOptions as ZlibCompressionOptions } from 'zlib'; export = CompressionPlugin; -declare class CompressionPlugin extends Plugin { - constructor(options?: CompressionPlugin.Options); +declare class CompressionPlugin extends Plugin { + constructor(options?: CompressionPlugin.Options); } declare namespace CompressionPlugin { - interface Options { + type AlgorithmCallback = (error: Error | null, result: Buffer) => void; + type Algorithm = (source: string, options: O, callback: AlgorithmCallback) => void; + + // NOTE: These are the compression algorithms exported by zlib. + type ZlibAlgorithm = 'deflate' | 'deflateRaw' | 'gzip'; + + interface BaseOptions { asset?: string; - algorithm?: string; cache?: boolean | string; test?: RegExp | RegExp[]; regExp?: RegExp | RegExp[]; threshold?: number; minRatio?: number; - - // zlib options - level?: number; - flush?: number; - chunkSize?: number; - windowBits?: number; - memLevel?: number; - strategy?: number; - dictionary?: any; } + + interface ZlibOptions extends BaseOptions { + algorithm?: ZlibAlgorithm; + compressionOptions?: ZlibCompressionOptions; + } + + interface CustomOptions extends BaseOptions { + algorithm: Algorithm; + compressionOptions?: O; + } + + type Options = ZlibOptions | CustomOptions; } From 3fc7e124637a16d269db2640fe40e9c4ddbc024a Mon Sep 17 00:00:00 2001 From: Rhys van der Waerden Date: Mon, 19 Nov 2018 11:56:16 +1100 Subject: [PATCH 016/792] compression-webpack-plugin: asset -> filename --- .../compression-webpack-plugin-tests.ts | 5 ++++- types/compression-webpack-plugin/index.d.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts b/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts index e162a6bcb2..44662c4177 100644 --- a/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts +++ b/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts @@ -6,7 +6,7 @@ new CompressionPlugin(); const config: Configuration = { plugins: [ new CompressionPlugin({ - asset: "[path].gz[query]", + filename: "[path].gz[query]", algorithm: "gzip", cache: true, test: /\.js$|\.html$/, @@ -20,6 +20,9 @@ const configDefaultAlgo = new CompressionPlugin({ compressionOptions: { level: 7 } }); +// $ExpectError +new CompressionPlugin({ asset: "[path].gz[query]" }); + const zlib: Configuration = { plugins: [ new CompressionPlugin({ diff --git a/types/compression-webpack-plugin/index.d.ts b/types/compression-webpack-plugin/index.d.ts index 9c66248776..4a6ccd290e 100644 --- a/types/compression-webpack-plugin/index.d.ts +++ b/types/compression-webpack-plugin/index.d.ts @@ -21,7 +21,7 @@ declare namespace CompressionPlugin { type ZlibAlgorithm = 'deflate' | 'deflateRaw' | 'gzip'; interface BaseOptions { - asset?: string; + filename?: string; cache?: boolean | string; test?: RegExp | RegExp[]; regExp?: RegExp | RegExp[]; From d74799987561f76db932b4bc40cfb814289101dc Mon Sep 17 00:00:00 2001 From: Rhys van der Waerden Date: Mon, 19 Nov 2018 12:08:39 +1100 Subject: [PATCH 017/792] compression-webpack-plugin: Update options - Add `include`/`exclude` - Remove `regExp` which was undocumented (possibly always wrong?) - Add `deleteOriginalAssets` - Prefer `ReadonlyArray` for string/regex options --- .../compression-webpack-plugin-tests.ts | 11 +++++++++-- types/compression-webpack-plugin/index.d.ts | 13 ++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts b/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts index 44662c4177..a679b7f599 100644 --- a/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts +++ b/types/compression-webpack-plugin/compression-webpack-plugin-tests.ts @@ -3,15 +3,22 @@ import CompressionPlugin = require('compression-webpack-plugin'); new CompressionPlugin(); +new CompressionPlugin({ + include: ["a"] as ReadonlyArray, + exclude: [/a/g] as ReadonlyArray, + test: "a", +}); + const config: Configuration = { plugins: [ new CompressionPlugin({ - filename: "[path].gz[query]", algorithm: "gzip", cache: true, + filename: "[path].gz[query]", + minRatio: 0.8, test: /\.js$|\.html$/, threshold: 10240, - minRatio: 0.8 + deleteOriginalAssets: true }) ] }; diff --git a/types/compression-webpack-plugin/index.d.ts b/types/compression-webpack-plugin/index.d.ts index 4a6ccd290e..8c399bbdd5 100644 --- a/types/compression-webpack-plugin/index.d.ts +++ b/types/compression-webpack-plugin/index.d.ts @@ -17,16 +17,19 @@ declare namespace CompressionPlugin { type AlgorithmCallback = (error: Error | null, result: Buffer) => void; type Algorithm = (source: string, options: O, callback: AlgorithmCallback) => void; - // NOTE: These are the compression algorithms exported by zlib. + // NOTE: These are the async compression algorithms on the zlib object. type ZlibAlgorithm = 'deflate' | 'deflateRaw' | 'gzip'; + type Pattern = string | RegExp | ReadonlyArray | ReadonlyArray; interface BaseOptions { - filename?: string; cache?: boolean | string; - test?: RegExp | RegExp[]; - regExp?: RegExp | RegExp[]; - threshold?: number; + deleteOriginalAssets?: boolean; + exclude?: Pattern; + filename?: string; + include?: Pattern; minRatio?: number; + test?: Pattern; + threshold?: number; } interface ZlibOptions extends BaseOptions { From 2087e1b9f13248e441fc923ab638a23bec69255c Mon Sep 17 00:00:00 2001 From: Rhys van der Waerden Date: Mon, 19 Nov 2018 12:09:14 +1100 Subject: [PATCH 018/792] compression-webpack-plugin: Add myself --- types/compression-webpack-plugin/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/compression-webpack-plugin/index.d.ts b/types/compression-webpack-plugin/index.d.ts index 8c399bbdd5..b03b655c69 100644 --- a/types/compression-webpack-plugin/index.d.ts +++ b/types/compression-webpack-plugin/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for compression-webpack-plugin 0.4 // Project: https://github.com/webpack-contrib/compression-webpack-plugin // Definitions by: Anton Kandybo +// Rhys van der Waerden // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 From f69b9883f0ab04fdb4c2d057f8a3b16ec288782e Mon Sep 17 00:00:00 2001 From: Rhys van der Waerden Date: Mon, 19 Nov 2018 12:13:49 +1100 Subject: [PATCH 019/792] compression-webpack-plugin: Bump version number --- types/compression-webpack-plugin/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/compression-webpack-plugin/index.d.ts b/types/compression-webpack-plugin/index.d.ts index b03b655c69..5d72f1fca8 100644 --- a/types/compression-webpack-plugin/index.d.ts +++ b/types/compression-webpack-plugin/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for compression-webpack-plugin 0.4 +// Type definitions for compression-webpack-plugin 2.0 // Project: https://github.com/webpack-contrib/compression-webpack-plugin // Definitions by: Anton Kandybo // Rhys van der Waerden From ead05a22eb89d1a00082c4eb62e8f6393c58399c Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Mon, 19 Nov 2018 08:19:12 -0500 Subject: [PATCH 020/792] Fix children type for react-native-dialog (#1) * Fix children type for react-native-dialog --- types/react-native-dialog/index.d.ts | 4 +++- .../react-native-dialog-tests.tsx | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/types/react-native-dialog/index.d.ts b/types/react-native-dialog/index.d.ts index 10e977f420..14d7458140 100644 --- a/types/react-native-dialog/index.d.ts +++ b/types/react-native-dialog/index.d.ts @@ -1,6 +1,8 @@ // Type definitions for react-native-dialog 4.0 // Project: https://github.com/mmazzarolo/react-native-dialog // Definitions by: MrLuje +// Stack Builders +// Esteban Ibarra // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -32,7 +34,7 @@ interface ButtonProps { interface ContainerProps { blurComponentIOS?: ReactNode; - children: JSX.Element[]; + children: React.ReactNode[]; /** * default: false */ diff --git a/types/react-native-dialog/react-native-dialog-tests.tsx b/types/react-native-dialog/react-native-dialog-tests.tsx index 151ee14af5..544025051c 100644 --- a/types/react-native-dialog/react-native-dialog-tests.tsx +++ b/types/react-native-dialog/react-native-dialog-tests.tsx @@ -2,6 +2,24 @@ import Dialog from "react-native-dialog"; import { createRef, Component } from "react"; class Example extends Component { + dynamicButtons() { + const buttonFunc = () => console.log('click'); + const buttons = [ + { label: 'Button 1', action: buttonFunc }, + { label: 'Button 2', action: buttonFunc }, + ]; + return buttons.map(({ label , action }) => + + ); + } + + singleButton() { + return ( null} />); + } + render() { const ref = createRef(); @@ -23,6 +41,8 @@ class Example extends Component { label="Validate" onPress={() => console.log("test")} /> + {this.dynamicButtons()} + {this.singleButton()} ); } From 2437acbc1cad793b1596fc0e3e5ed5318b0a8da9 Mon Sep 17 00:00:00 2001 From: IanStorm Date: Mon, 19 Nov 2018 19:33:40 +0100 Subject: [PATCH 021/792] Generated required package structure by running `dts-gen --dt` --- types/list-stream/index.d.ts | 39 ++++++++++++++++++++++++++ types/list-stream/list-stream-tests.ts | 0 types/list-stream/tsconfig.json | 22 +++++++++++++++ types/list-stream/tslint.json | 1 + 4 files changed, 62 insertions(+) create mode 100644 types/list-stream/index.d.ts create mode 100644 types/list-stream/list-stream-tests.ts create mode 100644 types/list-stream/tsconfig.json create mode 100644 types/list-stream/tslint.json diff --git a/types/list-stream/index.d.ts b/types/list-stream/index.d.ts new file mode 100644 index 0000000000..f331fcf838 --- /dev/null +++ b/types/list-stream/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for list-stream 1.0 +// Project: https://github.com/rvagg/list-stream +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/*~ If this module is a UMD module that exposes a global variable 'myLib' when + *~ loaded outside a module loader environment, declare that global here. + *~ Otherwise, delete this declaration. + */ +export as namespace myLib; + +/*~ If this module has methods, declare them as functions like so. + */ +export function myMethod(a: string): string; +export function myOtherMethod(a: number): number; + +/*~ You can declare types that are available via importing the module */ +export interface someType { + name: string; + length: number; + extras?: string[]; +} + +/*~ You can declare properties of the module using const, let, or var */ +export const myField: number; + +/*~ If there are types, properties, or methods inside dotted names + *~ of the module, declare them inside a 'namespace'. + */ +export namespace subProp { + /*~ For example, given this definition, someone could write: + *~ import { subProp } from 'yourModule'; + *~ subProp.foo(); + *~ or + *~ import * as yourMod from 'yourModule'; + *~ yourMod.subProp.foo(); + */ + export function foo(): void; +} \ No newline at end of file diff --git a/types/list-stream/list-stream-tests.ts b/types/list-stream/list-stream-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/types/list-stream/tsconfig.json b/types/list-stream/tsconfig.json new file mode 100644 index 0000000000..ce92e0529c --- /dev/null +++ b/types/list-stream/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "list-stream-tests.ts" + ] +} diff --git a/types/list-stream/tslint.json b/types/list-stream/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/list-stream/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 4b09a1e10024bbf4852f6b210066dae080fc39f8 Mon Sep 17 00:00:00 2001 From: IanStorm Date: Mon, 19 Nov 2018 19:35:07 +0100 Subject: [PATCH 022/792] Editing author information --- types/list-stream/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/list-stream/index.d.ts b/types/list-stream/index.d.ts index f331fcf838..4024bd51ee 100644 --- a/types/list-stream/index.d.ts +++ b/types/list-stream/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for list-stream 1.0 // Project: https://github.com/rvagg/list-stream -// Definitions by: My Self +// Definitions by: IanStorm // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /*~ If this module is a UMD module that exposes a global variable 'myLib' when From 1074143fd85b1e4e1cc17b8ace89cf2c9c8a5b07 Mon Sep 17 00:00:00 2001 From: IanStorm Date: Mon, 19 Nov 2018 20:34:19 +0100 Subject: [PATCH 023/792] Added actual type definition and tests --- types/list-stream/index.d.ts | 47 ++++++++++---------------- types/list-stream/list-stream-tests.ts | 37 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/types/list-stream/index.d.ts b/types/list-stream/index.d.ts index 4024bd51ee..8b97483cdb 100644 --- a/types/list-stream/index.d.ts +++ b/types/list-stream/index.d.ts @@ -3,37 +3,26 @@ // Definitions by: IanStorm // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/*~ If this module is a UMD module that exposes a global variable 'myLib' when - *~ loaded outside a module loader environment, declare that global here. - *~ Otherwise, delete this declaration. - */ -export as namespace myLib; +/// -/*~ If this module has methods, declare them as functions like so. - */ -export function myMethod(a: string): string; -export function myOtherMethod(a: number): number; -/*~ You can declare types that are available via importing the module */ -export interface someType { - name: string; - length: number; - extras?: string[]; +import { Duplex, DuplexOptions } from "stream"; + +declare namespace ListStream { } -/*~ You can declare properties of the module using const, let, or var */ -export const myField: number; +declare class ListStream extends Duplex { + constructor(callback?: (err: Error, data: any[]) => void); + constructor(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void); -/*~ If there are types, properties, or methods inside dotted names - *~ of the module, declare them inside a 'namespace'. - */ -export namespace subProp { - /*~ For example, given this definition, someone could write: - *~ import { subProp } from 'yourModule'; - *~ subProp.foo(); - *~ or - *~ import * as yourMod from 'yourModule'; - *~ yourMod.subProp.foo(); - */ - export function foo(): void; -} \ No newline at end of file + static obj(callback?: (err: Error, data: any[]) => void): ListStream; + static obj(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void): ListStream; + + append(chunk: any): void; + duplicate(): ListStream; + end(): void; + get(index: number): any; + length: number; +} + +export = ListStream; diff --git a/types/list-stream/list-stream-tests.ts b/types/list-stream/list-stream-tests.ts index e69de29bb2..aefb41bf0c 100644 --- a/types/list-stream/list-stream-tests.ts +++ b/types/list-stream/list-stream-tests.ts @@ -0,0 +1,37 @@ +import * as ListStream from "list-stream"; + +let chunk: any = "chunk"; +let listStream: ListStream; +let num: number = 1; + +listStream = new ListStream((err: Error, data: any[]) => { + if (err) { throw err; } + console.log(data.length); + for (const date of data) { + console.log(date); + } +}); +listStream = new ListStream({ objectMode: true }, (err: Error, data: any[]) => { + if (err) { throw err; } + console.log(data.length); + for (const date of data) { + console.log(date); + } +}); +listStream = ListStream.obj((err: Error, data: any[]) => { + if (err) { throw err; } + console.log(data.length); + for (const date of data) { + console.log(date); + } +}); + +listStream.append(chunk); + +listStream = listStream.duplicate(); + +listStream.end(); + +chunk = listStream.get(num); + +num = listStream.length; From 8bd0adc2267e15543719193222ccf5d202234646 Mon Sep 17 00:00:00 2001 From: IanStorm Date: Mon, 19 Nov 2018 20:46:35 +0100 Subject: [PATCH 024/792] Added `strictFunctionTypes` inside `tsconfig.json` as required for Merge Request --- types/list-stream/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/list-stream/tsconfig.json b/types/list-stream/tsconfig.json index ce92e0529c..52ec1c73e1 100644 --- a/types/list-stream/tsconfig.json +++ b/types/list-stream/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 0ee6ec5d83ce1b1be83a95f67674afc39998d871 Mon Sep 17 00:00:00 2001 From: IanStorm Date: Mon, 19 Nov 2018 21:04:02 +0100 Subject: [PATCH 025/792] Fixed issues raised by `npm test`: * `no-consecutive-blank-lines` * `no-inferrable-types` --- types/list-stream/index.d.ts | 1 - types/list-stream/list-stream-tests.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/types/list-stream/index.d.ts b/types/list-stream/index.d.ts index 8b97483cdb..226d4c09ab 100644 --- a/types/list-stream/index.d.ts +++ b/types/list-stream/index.d.ts @@ -5,7 +5,6 @@ /// - import { Duplex, DuplexOptions } from "stream"; declare namespace ListStream { diff --git a/types/list-stream/list-stream-tests.ts b/types/list-stream/list-stream-tests.ts index aefb41bf0c..4b7fc2a6ab 100644 --- a/types/list-stream/list-stream-tests.ts +++ b/types/list-stream/list-stream-tests.ts @@ -2,7 +2,7 @@ import * as ListStream from "list-stream"; let chunk: any = "chunk"; let listStream: ListStream; -let num: number = 1; +let num = 1; listStream = new ListStream((err: Error, data: any[]) => { if (err) { throw err; } From a185047e8e2de73610c42992170ab0e2bb5b2118 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 20 Nov 2018 09:09:00 -0800 Subject: [PATCH 026/792] Update match-media-mock tests --- types/match-media-mock/match-media-mock-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/match-media-mock/match-media-mock-tests.ts b/types/match-media-mock/match-media-mock-tests.ts index dc35cff40b..6aa36407a9 100644 --- a/types/match-media-mock/match-media-mock-tests.ts +++ b/types/match-media-mock/match-media-mock-tests.ts @@ -7,7 +7,7 @@ matchMediaMock('(max-width: 991px)').matches // false matchMediaMock('(max-width: 1240px)').matches // true const mediaQueryList = matchMediaMock('(max-width: 991px)'); -const listener = (mql: MediaQueryList) => { }; +const listener = (mqle: MediaQueryListEvent) => { }; mediaQueryList.addListener(listener) mediaQueryList.removeListener(listener) From 4d019f2ef8d52b646c4e974fca498ecbd450335f Mon Sep 17 00:00:00 2001 From: Marko K Date: Tue, 20 Nov 2018 20:51:17 +0200 Subject: [PATCH 027/792] fix: allow StyleFunction for heatmap paint properties --- types/mapbox-gl/index.d.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 91fb68cd96..b45e1e8746 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -232,7 +232,7 @@ declare namespace mapboxgl { /** * The max number of pixels a user can shift the mouse pointer during a click for it to be * considered a valid click (as opposed to a mouse drag). - * + * * @default 3 */ clickTolerance?: number; @@ -242,7 +242,7 @@ declare namespace mapboxgl { * and Vector Tile web workers (this information is normally inaccessible from the main * Javascript thread). Information will be returned in a `resourceTiming` property of * relevant `data` events. - * + * * @default false */ collectResourceTiming?: boolean; @@ -250,7 +250,7 @@ declare namespace mapboxgl { /** * If `true`, symbols from multiple sources can collide with each other during collision * detection. If `false`, collision detection is run separately for the symbols in each source. - * + * * @default true */ crossSourceCollisions?: boolean; @@ -278,7 +278,7 @@ declare namespace mapboxgl { * Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. * This setting affects all symbol layers. This setting does not affect the duration of runtime * styling transitions or raster tile cross-fading. - * + * * @default 300 */ fadeDuration?: number; @@ -297,14 +297,14 @@ declare namespace mapboxgl { * 'CJK Unified Ideographs' and 'Hangul Syllables' ranges. In these ranges, font settings from * the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold). * The purpose of this option is to avoid bandwidth-intensive glyph server requests. - * + * * @default null */ localIdeographFontFamily?: string; /** * A string representing the position of the Mapbox wordmark on the map. - * + * * @default "bottom-left" */ logoPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; @@ -324,14 +324,14 @@ declare namespace mapboxgl { /** * The initial pitch (tilt) of the map, measured in degrees away from the plane of the * screen (0-60). - * + * * @default 0 */ pitch?: number; /** * If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled. - * + * * @default true */ pitchWithRotate?: boolean; @@ -339,14 +339,14 @@ declare namespace mapboxgl { /** * If `false`, the map won't attempt to re-request tiles once they expire per their HTTP * `cacheControl`/`expires` headers. - * + * * @default true */ refreshExpiredTiles?: boolean; /** * If `true`, multiple copies of the world will be rendered, when zoomed out. - * + * * @default true */ renderWorldCopies?: boolean; @@ -363,7 +363,7 @@ declare namespace mapboxgl { /** * A callback run before the Map makes a request for an external URL. The callback can be * used to modify the url, set headers, or set the credentials property for cross-origin requests. - * + * * @default null */ transformRequest?: TransformRequestFunction; @@ -377,13 +377,13 @@ declare namespace mapboxgl { /** * The maximum number of tiles stored in the tile cache for a given source. If omitted, the * cache will be dynamically sized based on the current viewport. - * + * * @default null */ maxTileCacheSize?: number; } - export type ResourceType = + export type ResourceType = | 'Unknown' | 'Style' | 'Source' @@ -692,7 +692,7 @@ declare namespace mapboxgl { clusterMaxZoom?: number; lineMetrics?: boolean; - + generateId?: boolean; } @@ -1476,13 +1476,13 @@ declare namespace mapboxgl { } export interface HeatmapPaint { - 'heatmap-radius'?: number | Expression; + 'heatmap-radius'?: number | StyleFunction | Expression; 'heatmap-radius-transition'?: Transition; 'heatmap-weight'?: number | StyleFunction | Expression; - 'heatmap-intensity'?: number | Expression; + 'heatmap-intensity'?: number | StyleFunction | Expression; 'heatmap-intensity-transition'?: Transition; - 'heatmap-color'?: string | Expression; - 'heatmap-opacity'?: number | Expression; + 'heatmap-color'?: string | StyleFunction | Expression; + 'heatmap-opacity'?: number | StyleFunction | Expression; 'heatmap-opacity-transition'?: Transition; } From 845918b6a86a6190c23da22b4d8def7ac9adeffb Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Tue, 20 Nov 2018 12:15:15 -0500 Subject: [PATCH 028/792] Add types for react-native-draggable-flatlist --- .../index.d.ts | 59 +++++++++++++++++++ .../react-native-draggable-flatlist-tests.tsx | 44 ++++++++++++++ .../tsconfig.json | 24 ++++++++ .../tslint.json | 1 + 4 files changed, 128 insertions(+) create mode 100644 types/react-native-draggable-flatlist/index.d.ts create mode 100644 types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx create mode 100644 types/react-native-draggable-flatlist/tsconfig.json create mode 100644 types/react-native-draggable-flatlist/tslint.json diff --git a/types/react-native-draggable-flatlist/index.d.ts b/types/react-native-draggable-flatlist/index.d.ts new file mode 100644 index 0000000000..0b96f0b3cd --- /dev/null +++ b/types/react-native-draggable-flatlist/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for react-native-draggable-flatlist 1.1 +// Project: https://github.com/computerjazz/react-native-draggable-flatlist#readme +// Definitions by: Stack Builders +// Esteban Ibarra +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { VirtualizedListWithoutRenderItemProps } from "react-native"; +import { Component } from "react"; + +export interface RenderItemInfo { + item: ItemR; + index: number; + move: () => void; + moveEnd: () => void; + isActive: boolean; +} + +export interface OnMoveEndInfo { + data: ReadonlyArray | null; + to: number; + from: number; + row: ItemM; +} + +interface DraggableFlatListProps extends VirtualizedListWithoutRenderItemProps { + /** + * Items to be rendered. + */ + data: ReadonlyArray | null; + + /** + * Function that returns updated ordering of data + */ + onMoveEnd?: (info: OnMoveEndInfo) => void; + + /** + * Function that is called when row becomes active. + */ + onMoveBegin?: (index: number) => void; + + /** + * Sets where scrolling begins. + * + * Default is 5 + */ + scrollPercent?: number; + + /** + * Function that calls move when the row should become active (in an onPress, onLongPress, etc). Calls moveEnd when the gesture is complete (in onPressOut). + */ + renderItem: (info: RenderItemInfo) => React.ReactElement | null; +} + +declare class DraggableFlatList extends Component> { + constructor(props: DraggableFlatListProps); +} + +export default DraggableFlatList; diff --git a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx new file mode 100644 index 0000000000..40d613e4ea --- /dev/null +++ b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx @@ -0,0 +1,44 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import DraggableFlatList, { RenderItemInfo } from 'react-native-draggable-flatlist'; + +interface Item { + name: string; + mail: string; +} + +class Example extends React.Component { + state = { + data: [ + { name: 'Esteban', mail: 'foo@foo.com' }, + { name: 'Xavier', mail: 'foo2@foo.com' }, + ] + }; + + renderItem({ item, index, move, moveEnd, isActive }: RenderItemInfo) { + return ( + + {index} + {item.name} + {item.mail} + + ); + } + + render() { + const { data } = this.state; + return ( + `draggable-item-${index}`} + scrollPercent={10} + onMoveEnd={({ data }) => this.setState({ data })} + ListFooterComponent={{'Hello'}} + /> + ); + } +} diff --git a/types/react-native-draggable-flatlist/tsconfig.json b/types/react-native-draggable-flatlist/tsconfig.json new file mode 100644 index 0000000000..b3c009feac --- /dev/null +++ b/types/react-native-draggable-flatlist/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react-native" + }, + "files": [ + "index.d.ts", + "react-native-draggable-flatlist-tests.tsx" + ] +} diff --git a/types/react-native-draggable-flatlist/tslint.json b/types/react-native-draggable-flatlist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-draggable-flatlist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 9e68f23ebb215d1d2cda8ff25652d79dddada69c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 20 Nov 2018 11:17:42 -0800 Subject: [PATCH 029/792] Update redux-action with redux 4.0 API --- types/redux-action/package.json | 3 +-- types/redux-action/redux-action-tests.ts | 17 ++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/types/redux-action/package.json b/types/redux-action/package.json index 0a14f5edc6..7cc600c266 100644 --- a/types/redux-action/package.json +++ b/types/redux-action/package.json @@ -1,7 +1,6 @@ { "private": true, "dependencies": { - "redux": "^3.6.0", - "redux-thunk": "^2.2.0" + "redux": "^4.0.1" } } diff --git a/types/redux-action/redux-action-tests.ts b/types/redux-action/redux-action-tests.ts index 2290ed9a3f..d1b065c08f 100644 --- a/types/redux-action/redux-action-tests.ts +++ b/types/redux-action/redux-action-tests.ts @@ -1,5 +1,4 @@ import * as ReduxAction from 'redux-action'; -import * as ReduxThunk from 'redux-thunk'; import * as Redux from 'redux'; interface Payload { @@ -11,7 +10,7 @@ const dispatch: Redux.Dispatch = (...args: any[]): any => { }; const actionCreator0 = ReduxAction.createAction('get items'); -dispatch(actionCreator0(1)) +actionCreator0(1)(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: Payload = action.payload; @@ -19,7 +18,7 @@ dispatch(actionCreator0(1)) const actionCreator1 = ReduxAction.createAction(); -dispatch(actionCreator1(1)) +actionCreator1(1)(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: Payload = action.payload; @@ -27,7 +26,7 @@ dispatch(actionCreator1(1)) const actionCreator2 = ReduxAction.createAction('get items', (name: string) => name); -dispatch(actionCreator2(1)) +actionCreator2(1)(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: string = action.payload; @@ -35,7 +34,7 @@ dispatch(actionCreator2(1)) const actionCreator3 = ReduxAction.createAction('get items', (name: string) => Promise.resolve(name)); -dispatch(actionCreator3(1)) +actionCreator3(1)(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: string = action.payload; @@ -43,7 +42,7 @@ dispatch(actionCreator3(1)) const actionCreator4 = ReduxAction.createAction((name: string) => name); -dispatch(actionCreator4(1)) +actionCreator4(1)(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: string = action.payload; @@ -51,7 +50,7 @@ dispatch(actionCreator4(1)) const actionCreator5 = ReduxAction.createAction((name: string) => 1); -dispatch(actionCreator5('items')) +actionCreator5('items')(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: number = action.payload; @@ -59,7 +58,7 @@ dispatch(actionCreator5('items')) const actionCreator6 = ReduxAction.createAction((name: string) => 1); -dispatch(actionCreator6('items', false)) +actionCreator6('items', false)(dispatch, () => { }) .then(action => { const type: string = action.type; const payload: number = action.payload; @@ -80,4 +79,4 @@ const reducer = ReduxAction.createReducer({ name: 'name' }, { } }); -const combinedReducer: Redux.Reducer = Redux.combineReducers({ reducer }); +const combinedReducer: Redux.Reducer<{ reducer: State }> = Redux.combineReducers<{ reducer: State }>({ reducer }); From fd052a6b5a37f5125f2f0b750090902ec41908fa Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 20 Nov 2018 11:31:32 -0800 Subject: [PATCH 030/792] Downcast Error types to ignore call signature This helps type inference work correctly. --- types/bluebird/bluebird-tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index 05ac5cc19c..8fe5db7538 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -313,7 +313,7 @@ fooOrBarProm = fooProm.caught((error: any) => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // $ExpectType Bluebird -fooProm.catch(Error, (reason: any) => { +fooProm.catch(Error as { new(message?: string): Error }, (reason: any) => { return; }); // $ExpectType Bluebird @@ -321,7 +321,7 @@ fooProm.catch(Promise.CancellationError, (reason: any) => { return; }); // $ExpectType Bluebird -fooProm.caught(Error, (reason: any) => { +fooProm.caught(Error as { new(message?: string): Error }, (reason: any) => { return; }); // $ExpectType Bluebird @@ -329,13 +329,13 @@ fooProm.caught(Promise.CancellationError, (reason: any) => { return; }); -fooOrBarProm = fooProm.catch(Error, (reason: any) => { +fooOrBarProm = fooProm.catch(Error as { new(message?: string): Error }, (reason: any) => { return bar; }); fooOrBarProm = fooProm.catch(Promise.CancellationError, (reason: any) => { return bar; }); -fooOrBarProm = fooProm.caught(Error, (reason: any) => { +fooOrBarProm = fooProm.caught(Error as { new(message?: string): Error }, (reason: any) => { return bar; }); fooOrBarProm = fooProm.caught(Promise.CancellationError, (reason: any) => { From f1d0311b61d2efdd39e82369b40906d39a7f4a13 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 20 Nov 2018 11:42:19 -0800 Subject: [PATCH 031/792] Fix unrelated lints --- types/db-migrate-base/db-migrate-base-tests.ts | 4 ++-- types/db-migrate-pg/db-migrate-pg-tests.ts | 2 +- types/project-oxford/project-oxford-tests.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/db-migrate-base/db-migrate-base-tests.ts b/types/db-migrate-base/db-migrate-base-tests.ts index 79d81a75f9..b094be1280 100644 --- a/types/db-migrate-base/db-migrate-base-tests.ts +++ b/types/db-migrate-base/db-migrate-base-tests.ts @@ -3,7 +3,7 @@ import * as DbMigrateBase from "db-migrate-base"; // Throw together a dummy driver -let db = {}; +let db = {} as DbMigrateBase.Base; let callback = (err: any, response: any) => { // Do nothing. @@ -318,4 +318,4 @@ db.runSqlAsync('DROP TABLE `pets`').then(onResolve); /// allAsync(sql, [params]) db.allAsync('SELECT * FROM `module_user` WHERE `?` = \'?\'', ['first_name', 'Test']).then(onResolve); -db.allAsync('SELECT * FROM `module_user`').then(onResolve); \ No newline at end of file +db.allAsync('SELECT * FROM `module_user`').then(onResolve); diff --git a/types/db-migrate-pg/db-migrate-pg-tests.ts b/types/db-migrate-pg/db-migrate-pg-tests.ts index adf2716074..b31d88e37d 100644 --- a/types/db-migrate-pg/db-migrate-pg-tests.ts +++ b/types/db-migrate-pg/db-migrate-pg-tests.ts @@ -3,7 +3,7 @@ import * as DbMigratePg from "db-migrate-pg"; // Throw together a dummy driver -let db = {}; +let db = {} as DbMigratePg.PgDriver; let callback = (err: any, response: any) => { // Do nothing. diff --git a/types/project-oxford/project-oxford-tests.ts b/types/project-oxford/project-oxford-tests.ts index d4c59de109..8b1dbec466 100644 --- a/types/project-oxford/project-oxford-tests.ts +++ b/types/project-oxford/project-oxford-tests.ts @@ -12,7 +12,7 @@ const {describe, it, before, after, beforeEach, afterEach} = null as any as { var client = new oxford.Client(process.env.OXFORD_KEY); // Store variables, no point in calling the api too often -var billFaces = []; +var billFaces = [] as string[]; var personGroupId = "uuid.v4()"; var personGroupId2 = "uuid.v4()"; var billPersonId: string; @@ -113,7 +113,7 @@ describe('Project Oxford Face API Test', function () { describe('#grouping()', function () { it('detects groups faces', function (done) { - var faceIds = []; + var faceIds = [] as string[]; this.timeout(10000); From ca53c065a52c288b7d8d3fb3bde5709c6d496f7c Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Tue, 20 Nov 2018 15:18:30 -0500 Subject: [PATCH 032/792] Revert changes of react-native-draggable-flatlist --- .../index.d.ts | 59 ------------------- .../react-native-draggable-flatlist-tests.tsx | 44 -------------- .../tsconfig.json | 24 -------- .../tslint.json | 1 - 4 files changed, 128 deletions(-) delete mode 100644 types/react-native-draggable-flatlist/index.d.ts delete mode 100644 types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx delete mode 100644 types/react-native-draggable-flatlist/tsconfig.json delete mode 100644 types/react-native-draggable-flatlist/tslint.json diff --git a/types/react-native-draggable-flatlist/index.d.ts b/types/react-native-draggable-flatlist/index.d.ts deleted file mode 100644 index 0b96f0b3cd..0000000000 --- a/types/react-native-draggable-flatlist/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Type definitions for react-native-draggable-flatlist 1.1 -// Project: https://github.com/computerjazz/react-native-draggable-flatlist#readme -// Definitions by: Stack Builders -// Esteban Ibarra -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 - -import { VirtualizedListWithoutRenderItemProps } from "react-native"; -import { Component } from "react"; - -export interface RenderItemInfo { - item: ItemR; - index: number; - move: () => void; - moveEnd: () => void; - isActive: boolean; -} - -export interface OnMoveEndInfo { - data: ReadonlyArray | null; - to: number; - from: number; - row: ItemM; -} - -interface DraggableFlatListProps extends VirtualizedListWithoutRenderItemProps { - /** - * Items to be rendered. - */ - data: ReadonlyArray | null; - - /** - * Function that returns updated ordering of data - */ - onMoveEnd?: (info: OnMoveEndInfo) => void; - - /** - * Function that is called when row becomes active. - */ - onMoveBegin?: (index: number) => void; - - /** - * Sets where scrolling begins. - * - * Default is 5 - */ - scrollPercent?: number; - - /** - * Function that calls move when the row should become active (in an onPress, onLongPress, etc). Calls moveEnd when the gesture is complete (in onPressOut). - */ - renderItem: (info: RenderItemInfo) => React.ReactElement | null; -} - -declare class DraggableFlatList extends Component> { - constructor(props: DraggableFlatListProps); -} - -export default DraggableFlatList; diff --git a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx deleted file mode 100644 index 40d613e4ea..0000000000 --- a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import * as React from 'react'; -import { TouchableOpacity, Text } from 'react-native'; -import DraggableFlatList, { RenderItemInfo } from 'react-native-draggable-flatlist'; - -interface Item { - name: string; - mail: string; -} - -class Example extends React.Component { - state = { - data: [ - { name: 'Esteban', mail: 'foo@foo.com' }, - { name: 'Xavier', mail: 'foo2@foo.com' }, - ] - }; - - renderItem({ item, index, move, moveEnd, isActive }: RenderItemInfo) { - return ( - - {index} - {item.name} - {item.mail} - - ); - } - - render() { - const { data } = this.state; - return ( - `draggable-item-${index}`} - scrollPercent={10} - onMoveEnd={({ data }) => this.setState({ data })} - ListFooterComponent={{'Hello'}} - /> - ); - } -} diff --git a/types/react-native-draggable-flatlist/tsconfig.json b/types/react-native-draggable-flatlist/tsconfig.json deleted file mode 100644 index b3c009feac..0000000000 --- a/types/react-native-draggable-flatlist/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true, - "jsx": "react-native" - }, - "files": [ - "index.d.ts", - "react-native-draggable-flatlist-tests.tsx" - ] -} diff --git a/types/react-native-draggable-flatlist/tslint.json b/types/react-native-draggable-flatlist/tslint.json deleted file mode 100644 index 3db14f85ea..0000000000 --- a/types/react-native-draggable-flatlist/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "dtslint/dt.json" } From dc6cea2e1ed814f51b9211f2a31bf752666a3890 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 20 Nov 2018 12:36:47 -0800 Subject: [PATCH 033/792] Fix CI failure 1. Use 3.1 and 3.2-compatible fix for match-media-mock. Specify a this-parameter. 2. redux-action requires TS 2.3 so that type parameter defaults and mapped types from redux 4.0 work. --- types/match-media-mock/match-media-mock-tests.ts | 2 +- types/redux-action/index.d.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/types/match-media-mock/match-media-mock-tests.ts b/types/match-media-mock/match-media-mock-tests.ts index 6aa36407a9..25fe411dd1 100644 --- a/types/match-media-mock/match-media-mock-tests.ts +++ b/types/match-media-mock/match-media-mock-tests.ts @@ -7,7 +7,7 @@ matchMediaMock('(max-width: 991px)').matches // false matchMediaMock('(max-width: 1240px)').matches // true const mediaQueryList = matchMediaMock('(max-width: 991px)'); -const listener = (mqle: MediaQueryListEvent) => { }; +const listener = function (this: MediaQueryList) { }; mediaQueryList.addListener(listener) mediaQueryList.removeListener(listener) diff --git a/types/redux-action/index.d.ts b/types/redux-action/index.d.ts index dc5b9e5229..51c3cc3b61 100644 --- a/types/redux-action/index.d.ts +++ b/types/redux-action/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/coderhaoxin/redux-action // Definitions by: newraina // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 /** * inspired by @types/redux-actions, thanks. From ebbf64f76b0b702ca0591ffa43c3586f994c9e43 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 20 Nov 2018 15:56:58 -0800 Subject: [PATCH 034/792] Work around 3.2 inference change using overloads Notes: 1. I only duplicated overloads to get 2 * n instead of 2 * n overloads needed to support every combination of constructor function/other. 2. I deleted the duplicate R vs U | R overloads for `catch` since they were equivalent; I don't think the R overloads were ever used. 3. The original overload is now Constructor | CatchFilter; I haven't figured out why yet, but normal classes don't use the new Constructor-only overload. Only constructor functions do. --- types/bluebird/bluebird-tests.ts | 8 +- types/bluebird/index.d.ts | 277 +++++++++++++++++++++---------- 2 files changed, 190 insertions(+), 95 deletions(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index 8fe5db7538..05ac5cc19c 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -313,7 +313,7 @@ fooOrBarProm = fooProm.caught((error: any) => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // $ExpectType Bluebird -fooProm.catch(Error as { new(message?: string): Error }, (reason: any) => { +fooProm.catch(Error, (reason: any) => { return; }); // $ExpectType Bluebird @@ -321,7 +321,7 @@ fooProm.catch(Promise.CancellationError, (reason: any) => { return; }); // $ExpectType Bluebird -fooProm.caught(Error as { new(message?: string): Error }, (reason: any) => { +fooProm.caught(Error, (reason: any) => { return; }); // $ExpectType Bluebird @@ -329,13 +329,13 @@ fooProm.caught(Promise.CancellationError, (reason: any) => { return; }); -fooOrBarProm = fooProm.catch(Error as { new(message?: string): Error }, (reason: any) => { +fooOrBarProm = fooProm.catch(Error, (reason: any) => { return bar; }); fooOrBarProm = fooProm.catch(Promise.CancellationError, (reason: any) => { return bar; }); -fooOrBarProm = fooProm.caught(Error as { new(message?: string): Error }, (reason: any) => { +fooOrBarProm = fooProm.caught(Error, (reason: any) => { return bar; }); fooOrBarProm = fooProm.caught(Promise.CancellationError, (reason: any) => { diff --git a/types/bluebird/index.d.ts b/types/bluebird/index.d.ts index 091dbe6e7a..1f8768498a 100644 --- a/types/bluebird/index.d.ts +++ b/types/bluebird/index.d.ts @@ -35,7 +35,8 @@ * THE SOFTWARE. */ -type CatchFilter = (new (...args: any[]) => E) | ((error: E) => boolean) | (object & E); +type Constructor = new (...args: any[]) => E +type CatchFilter = ((error: E) => boolean) | (object & E); type IterableItem = R extends Iterable ? U : never; type IterableOrNever = Extract>; type Resolvable = R | PromiseLike; @@ -85,69 +86,73 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * * Alias `.caught();` for compatibility with earlier ECMAScript version. */ - catch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, - filter5: CatchFilter, - onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable, - ): Bluebird; catch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, - filter5: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, + filter5: Constructor, onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable, ): Bluebird; - catch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, - onReject: (error: E1 | E2 | E3 | E4) => Resolvable, - ): Bluebird; + catch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, + filter5: Constructor | CatchFilter, + onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable, + ): Bluebird; catch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, + onReject: (error: E1 | E2 | E3 | E4) => Resolvable, + ): Bluebird; + + catch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, onReject: (error: E1 | E2 | E3 | E4) => Resolvable, ): Bluebird; - catch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - onReject: (error: E1 | E2 | E3) => Resolvable, - ): Bluebird; catch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + onReject: (error: E1 | E2 | E3) => Resolvable, + ): Bluebird; + + catch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, onReject: (error: E1 | E2 | E3) => Resolvable, ): Bluebird; - catch( - filter1: CatchFilter, - filter2: CatchFilter, - onReject: (error: E1 | E2) => Resolvable, - ): Bluebird; catch( - filter1: CatchFilter, - filter2: CatchFilter, + filter1: Constructor, + filter2: Constructor, + onReject: (error: E1 | E2) => Resolvable, + ): Bluebird; + + catch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, onReject: (error: E1 | E2) => Resolvable, ): Bluebird; - catch( - filter1: CatchFilter, - onReject: (error: E1) => Resolvable, - ): Bluebird; catch( - filter1: CatchFilter, + filter1: Constructor, + onReject: (error: E1) => Resolvable, + ): Bluebird; + + catch( + filter1: Constructor | CatchFilter, onReject: (error: E1) => Resolvable, ): Bluebird; @@ -201,33 +206,63 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { tapCatch(onReject: (error?: any) => Resolvable): Bluebird; tapCatch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, - filter5: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, + filter5: Constructor, + onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable, + ): Bluebird; + tapCatch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, + filter5: Constructor | CatchFilter, onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable, ): Bluebird; tapCatch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, + onReject: (error: E1 | E2 | E3 | E4) => Resolvable, + ): Bluebird; + tapCatch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, onReject: (error: E1 | E2 | E3 | E4) => Resolvable, ): Bluebird; tapCatch( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + onReject: (error: E1 | E2 | E3) => Resolvable, + ): Bluebird; + tapCatch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, onReject: (error: E1 | E2 | E3) => Resolvable, ): Bluebird; tapCatch( - filter1: CatchFilter, - filter2: CatchFilter, + filter1: Constructor, + filter2: Constructor, + onReject: (error: E1 | E2) => Resolvable, + ): Bluebird; + tapCatch( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, onReject: (error: E1 | E2) => Resolvable, ): Bluebird; tapCatch( - filter1: CatchFilter, + filter1: Constructor, + onReject: (error: E1) => Resolvable, + ): Bluebird; + tapCatch( + filter1: Constructor | CatchFilter, onReject: (error: E1) => Resolvable, ): Bluebird; @@ -376,33 +411,63 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { // No need to be specific about Error types in these overrides, since there's no handler function catchReturn( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, - filter5: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, + filter5: Constructor, value: U, ): Bluebird; catchReturn( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, + filter5: Constructor | CatchFilter, value: U, ): Bluebird; catchReturn( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, value: U, ): Bluebird; catchReturn( - filter1: CatchFilter, - filter2: CatchFilter, + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, value: U, ): Bluebird; catchReturn( - filter1: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + value: U, + ): Bluebird; + catchReturn( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + value: U, + ): Bluebird; + catchReturn( + filter1: Constructor, + filter2: Constructor, + value: U, + ): Bluebird; + catchReturn( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + value: U, + ): Bluebird; + catchReturn( + filter1: Constructor, + value: U, + ): Bluebird; + catchReturn( + filter1: Constructor | CatchFilter, value: U, ): Bluebird; @@ -420,33 +485,63 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { // No need to be specific about Error types in these overrides, since there's no handler function catchThrow( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, - filter5: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, + filter5: Constructor, reason: Error, ): Bluebird; catchThrow( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, - filter4: CatchFilter, + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, + filter5: Constructor | CatchFilter, reason: Error, ): Bluebird; catchThrow( - filter1: CatchFilter, - filter2: CatchFilter, - filter3: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + filter4: Constructor, reason: Error, ): Bluebird; catchThrow( - filter1: CatchFilter, - filter2: CatchFilter, + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + filter4: Constructor | CatchFilter, reason: Error, ): Bluebird; catchThrow( - filter1: CatchFilter, + filter1: Constructor, + filter2: Constructor, + filter3: Constructor, + reason: Error, + ): Bluebird; + catchThrow( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + filter3: Constructor | CatchFilter, + reason: Error, + ): Bluebird; + catchThrow( + filter1: Constructor, + filter2: Constructor, + reason: Error, + ): Bluebird; + catchThrow( + filter1: Constructor | CatchFilter, + filter2: Constructor | CatchFilter, + reason: Error, + ): Bluebird; + catchThrow( + filter1: Constructor, + reason: Error, + ): Bluebird; + catchThrow( + filter1: Constructor | CatchFilter, reason: Error, ): Bluebird; From d2dd41340a12ebef17e104a61309611a51cf1183 Mon Sep 17 00:00:00 2001 From: Yann Normand Date: Wed, 21 Nov 2018 10:25:41 +1000 Subject: [PATCH 035/792] downgrade to Typescript 2.8 --- types/react-big-calendar/index.d.ts | 2 +- .../react-big-calendar-tests.tsx | 118 +++++++++--------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/types/react-big-calendar/index.d.ts b/types/react-big-calendar/index.d.ts index 0d4da60aa4..89e6f0eead 100644 --- a/types/react-big-calendar/index.d.ts +++ b/types/react-big-calendar/index.d.ts @@ -7,7 +7,7 @@ // Paul Potsides // janb87 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.9 +// TypeScript Version: 2.8 import { Validator } from 'prop-types'; import * as React from 'react'; diff --git a/types/react-big-calendar/react-big-calendar-tests.tsx b/types/react-big-calendar/react-big-calendar-tests.tsx index 918c352e0c..fd1e70f929 100644 --- a/types/react-big-calendar/react-big-calendar-tests.tsx +++ b/types/react-big-calendar/react-big-calendar-tests.tsx @@ -61,70 +61,70 @@ class CalendarResource { } { + class MyCalendar extends BigCalendar {} + // Full API Example Test - based on API Documentation // http://intljusticemission.github.io/react-big-calendar/examples/index.html#api class FullAPIExample extends React.Component> { render() { return ( - - {...this.props} - date={new Date()} - view={'day'} - events={getEvents()} - onNavigate={(newDate: Date, view: View, action: Navigate) => { }} - onView={(view: View) => { }} - onSelectSlot={(slotInfo) => { - const start = slotInfo.start; - const end = slotInfo.end; - const slots = slotInfo.slots; - }} - onSelectEvent={(event) => { }} - onSelecting={(slotInfo) => { - const start = slotInfo.start; - const end = slotInfo.end; - return true; - }} - views={['day']} - toolbar={true} - popup={true} - popupOffset={20} - selectable={true} - step={20} - rtl={true} - eventPropGetter={(event, start, end, isSelected) => ({ className: 'some-class' })} - titleAccessor={'title'} - allDayAccessor={(event: CalendarEvent) => !!event.allDay} - startAccessor={'start'} - endAccessor={(event: CalendarEvent) => event.end || event.start} - min={new Date()} - max={new Date()} - scrollToTime={new Date()} - formats={{ - dateFormat: "h a", - agendaDateFormat: (date: Date, culture?: string, localizer?: object) => "some-format", - dayRangeHeaderFormat: (range: DateRange, culture?: string, localizer?: object) => "some-format" - }} - messages={{}} - timeslots={24} - defaultView={'month'} - className={'my-calendar'} - elementProps={{ id: 'myCalendar' }} - components={{ - event: Event, - agenda: { - event: EventAgenda - }, - toolbar: Toolbar, - eventWrapper: EventWrapper, - }} - dayPropGetter={customDayPropGetter} - slotPropGetter={customSlotPropGetter} - defaultDate={new Date()} - resources={getResources()} - resourceAccessor={event => event.resourceId} - resourceIdAccessor={resource => resource.id} - resourceTitleAccessor={resource => resource.title} - /> + { }} + onView={(view: View) => { }} + onSelectSlot={(slotInfo) => { + const start = slotInfo.start; + const end = slotInfo.end; + const slots = slotInfo.slots; + }} + onSelectEvent={(event) => { }} + onSelecting={(slotInfo) => { + const start = slotInfo.start; + const end = slotInfo.end; + return true; + }} + views={['day']} + toolbar={true} + popup={true} + popupOffset={20} + selectable={true} + step={20} + rtl={true} + eventPropGetter={(event, start, end, isSelected) => ({ className: 'some-class' })} + titleAccessor={'title'} + allDayAccessor={(event: CalendarEvent) => !!event.allDay} + startAccessor={'start'} + endAccessor={(event: CalendarEvent) => event.end || event.start} + min={new Date()} + max={new Date()} + scrollToTime={new Date()} + formats={{ + dateFormat: "h a", + agendaDateFormat: (date: Date, culture?: string, localizer?: object) => "some-format", + dayRangeHeaderFormat: (range: DateRange, culture?: string, localizer?: object) => "some-format" + }} + messages={{}} + timeslots={24} + defaultView={'month'} + className={'my-calendar'} + elementProps={{ id: 'myCalendar' }} + components={{ + event: Event, + agenda: { + event: EventAgenda + }, + toolbar: Toolbar, + eventWrapper: EventWrapper, + }} + dayPropGetter={customDayPropGetter} + slotPropGetter={customSlotPropGetter} + defaultDate={new Date()} + resources={getResources()} + resourceAccessor={event => event.resourceId} + resourceIdAccessor={resource => resource.id} + resourceTitleAccessor={resource => resource.title} /> ); } } From 6187a17f6d944d1c7b57bb8c3b2ee472fe3cc9ee Mon Sep 17 00:00:00 2001 From: Alexandre Parent Date: Tue, 20 Nov 2018 19:25:52 -0500 Subject: [PATCH 036/792] Added a use for expect 'checker' with a callback I often use expect(Object, CallbackHandler) because expect((Response) => any, CallbackHandler) doesn't exist. On the other hand, making callback nullable will allow those using it without callback to keep doing it. --- types/supertest/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/supertest/index.d.ts b/types/supertest/index.d.ts index 77418352f9..5ac03df42d 100644 --- a/types/supertest/index.d.ts +++ b/types/supertest/index.d.ts @@ -24,7 +24,7 @@ declare namespace supertest { serverAddress(app: any, path: string): string; expect(status: number, callback?: CallbackHandler): this; expect(status: number, body: any, callback?: CallbackHandler): this; - expect(checker: (res: Response) => any): this; + expect(checker: (res: Response) => any, callback?: CallbackHandler): this; expect(body: string, callback?: CallbackHandler): this; expect(body: RegExp, callback?: CallbackHandler): this; expect(body: Object, callback?: CallbackHandler): this; From 3daac759f4ce410664691073d7a16f735e5fe66a Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Wed, 21 Nov 2018 21:46:45 +1100 Subject: [PATCH 037/792] ansicolors: accurate types with recursion support --- types/ansicolors/index.d.ts | 44 +++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/types/ansicolors/index.d.ts b/types/ansicolors/index.d.ts index 6750283895..e82fb47dd7 100644 --- a/types/ansicolors/index.d.ts +++ b/types/ansicolors/index.d.ts @@ -1,8 +1,44 @@ // Type definitions for ansicolors // Project: https://github.com/thlorenz/ansicolors -// Definitions by: rogierschouten +// Definitions by: Benjamin Arthur Lupton // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare var colors: { [index: string]: (s: string) => string; }; -export = colors; +interface Colors extends String { + white: Colors + black: Colors + blue: Colors + cyan: Colors + green: Colors + magenta: Colors + red: Colors + yellow: Colors + brightBlack: Colors + brightRed: Colors + brightGreen: Colors + brightYellow: Colors + brightBlue: Colors + brightMagenta: Colors + brightCyan: Colors + brightWhite: Colors + bgBlack: Colors + bgRed: Colors + bgGreen: Colors + bgYellow: Colors + bgBlue: Colors + bgMagenta: Colors + bgCyan: Colors + bgWhite: Colors + bgBrightBlack: Colors + bgBrightRed: Colors + bgBrightGreen: Colors + bgBrightYellow: Colors + bgBrightBlue: Colors + bgBrightMagenta: Colors + bgBrightCyan: Colors + bgBrightWhite: Colors + open: Colors + close: Colors + colors: Colors +} +declare var colors: Colors +export default colors From cb3647d767af0964db8616dda47adc4ac0a90f5c Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Wed, 21 Nov 2018 14:30:25 -0500 Subject: [PATCH 038/792] Added missing methods and properties along with result type for CommandCursor --- types/mongodb/index.d.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index ab4d2f4c02..458aef1fc5 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -19,6 +19,7 @@ // Mikael Lirbank // Hector Ribes // Florian Richter +// Erik Christensen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -450,7 +451,7 @@ export class Db extends EventEmitter { indexInformation(name: string, options?: { full?: boolean, readPreference?: ReadPreference | string }): Promise; indexInformation(name: string, options: { full?: boolean, readPreference?: ReadPreference | string }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#listCollections */ - listCollections(filter?: Object, options?: { batchSize?: number, readPreference?: ReadPreference | string }): CommandCursor; + listCollections(filter?: Object, options?: { nameOnly?: boolean, batchSize?: number, readPreference?: ReadPreference | string, session?: ClientSession }): CommandCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#profilingInfo */ /** @deprecated Query the system.profile collection directly. */ profilingInfo(callback: MongoCallback): void; @@ -1578,24 +1579,30 @@ export class AggregationCursor extends Readable { unwind(field: string): AggregationCursor; } +/** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#~resultCallback */ +export type CommandCursorResult = any | void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html */ export class CommandCursor extends Readable { + /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#hasNext */ + hasNext(): Promise; + /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#hasNext */ + hasNext(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#batchSize */ batchSize(value: number): CommandCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#clone */ clone(): CommandCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#close */ - close(): Promise; - close(callback: MongoCallback): void; + close(): Promise; + close(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#each */ - each(callback: MongoCallback): void; + each(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#isClosed */ isClosed(): boolean; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#maxTimeMS */ maxTimeMS(value: number): CommandCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#next */ - next(): Promise; - next(callback: MongoCallback): void; + next(): Promise; + next(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#read */ read(size: number): string | Buffer | void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/CommandCursor.html#rewind */ From 17af5405cbaa196d9f0766d3eda0374604fc0fda Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 21 Nov 2018 11:34:35 -0800 Subject: [PATCH 039/792] More TS 3.2 DOM updates Unlike the other PR, these updates should not go in until 3.2 is out, since they rely on the following additions: 1. webrtc 2. web-animations 3. geometry-dom I left these packages in to make it easier to upgrade and edited them where needed, but I removed the dependencies on them in other Definitely Typed packages. --- types/peerjs/index.d.ts | 6 +- types/skyway/index.d.ts | 6 +- types/w3c-generic-sensor/index.d.ts | 6 +- types/w3c-screen-orientation/index.d.ts | 2 +- types/web-animations-js/index.d.ts | 25 +++------ types/webrtc/RTCPeerConnection.d.ts | 75 +++++++++++++------------ 6 files changed, 53 insertions(+), 67 deletions(-) diff --git a/types/peerjs/index.d.ts b/types/peerjs/index.d.ts index 4ca88fd50b..faf99dc9b3 100644 --- a/types/peerjs/index.d.ts +++ b/types/peerjs/index.d.ts @@ -2,9 +2,7 @@ // Project: http://peerjs.com/ // Definitions by: Toshiya Nakakura // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 - -/// +// TypeScript Version: 3.2 declare namespace PeerJs{ interface PeerJSOption{ @@ -13,7 +11,7 @@ declare namespace PeerJs{ port?: number; path?: string; secure?: boolean; - config?: RTCPeerConnectionConfig; + config?: RTCConfiguration; debug?: number; } diff --git a/types/skyway/index.d.ts b/types/skyway/index.d.ts index eb73937178..e396f8cff0 100644 --- a/types/skyway/index.d.ts +++ b/types/skyway/index.d.ts @@ -2,9 +2,7 @@ // Project: http://nttcom.github.io/skyway/ // Definitions by: Toshiya Nakakura // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 - -/// +// TypeScript Version: 3.2 declare namespace PeerJs{ interface PeerJSOption{ @@ -14,7 +12,7 @@ declare namespace PeerJs{ path?: string; secure?: boolean; turn?: boolean; - config?: RTCPeerConnectionConfig; + config?: RTCConfiguration; debug?: number; } diff --git a/types/w3c-generic-sensor/index.d.ts b/types/w3c-generic-sensor/index.d.ts index 40f6db6301..bec987d04f 100644 --- a/types/w3c-generic-sensor/index.d.ts +++ b/types/w3c-generic-sensor/index.d.ts @@ -2,12 +2,10 @@ // Project: https://www.w3.org/TR/generic-sensor/ // Definitions by: Kenneth Rohde Christiansen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 +// TypeScript Version: 3.2 // Explainer: https://www.w3.org/TR/motion-sensors/ -/// - declare class SensorErrorEvent extends Event { constructor(type: string, errorEventInitDict: SensorErrorEventInit); readonly error: Error; @@ -82,7 +80,7 @@ declare class UncalibratedMagnetometer extends Sensor { // Orientation Sensor: https://www.w3.org/TR/orientation-sensor/ -type RotationMatrixType = Float32Array | Float64Array | GeometryDom.DOMMatrix; +type RotationMatrixType = Float32Array | Float64Array | DOMMatrix; declare class OrientationSensor extends Sensor { readonly quaternion?: number[]; diff --git a/types/w3c-screen-orientation/index.d.ts b/types/w3c-screen-orientation/index.d.ts index 7cac6c33f3..74fee2ecb6 100644 --- a/types/w3c-screen-orientation/index.d.ts +++ b/types/w3c-screen-orientation/index.d.ts @@ -2,8 +2,8 @@ // Project: https://www.w3.org/TR/screen-orientation/ // Definitions by: Kenneth Rohde Christiansen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2 -type OrientationType = "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary"; type ScreenOrientationLockType = "any" | "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary"; interface ScreenOrientation extends EventTarget { diff --git a/types/web-animations-js/index.d.ts b/types/web-animations-js/index.d.ts index 54c0b8c01b..c317675727 100644 --- a/types/web-animations-js/index.d.ts +++ b/types/web-animations-js/index.d.ts @@ -2,10 +2,10 @@ // Project: https://github.com/web-animations/web-animations-js // Definitions by: Kristian Moerch // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2 type AnimationEffectTimingFillMode = "none" | "forwards" | "backwards" | "both" | "auto"; type AnimationEffectTimingPlaybackDirection = "normal" | "reverse" | "alternate" | "alternate-reverse"; -type AnimationPlayState = "idle" | "running" | "paused" | "finished"; interface AnimationPlaybackEvent { target: Animation; @@ -68,18 +68,7 @@ interface ComputedTimingProperties { currentIteration: number | null; } -declare class KeyframeEffect implements AnimationEffectReadOnly { - constructor(target: HTMLElement, effect: AnimationKeyFrame | AnimationKeyFrame[], timing: number | AnimationEffectTiming, id?: string); - activeDuration: number; - onsample: (timeFraction: number | null, effect: KeyframeEffect, animation: Animation) => void | undefined; - parent: KeyframeEffect | null; - target: HTMLElement; - timing: number; - getComputedTiming(): ComputedTimingProperties; - getFrames(): AnimationKeyFrame[]; - remove(): void; -} -type AnimationEventListener = (this: Animation, evt: AnimationPlaybackEvent) => any; +type AnimationEventListener = ((this: Animation, evt: AnimationPlaybackEvent) => any) | null; interface Animation extends EventTarget { currentTime: number | null; @@ -88,7 +77,7 @@ interface Animation extends EventTarget { onfinish: AnimationEventListener; readonly playState: AnimationPlayState; playbackRate: number; - startTime: number; + startTime: number | null; cancel(): void; finish(): void; pause(): void; @@ -96,15 +85,15 @@ interface Animation extends EventTarget { reverse(): void; addEventListener(type: "finish" | "cancel", handler: EventListener): void; removeEventListener(type: "finish" | "cancel", handler: EventListener): void; - effect: AnimationEffectReadOnly; + effect: AnimationEffect | null; readonly finished: Promise; readonly ready: Promise; - timeline: AnimationTimeline; + timeline: AnimationTimeline | null; } declare var Animation: { prototype: Animation; - new(effect?: AnimationEffectReadOnly, timeline?: AnimationTimeline): Animation; + new(effect?: AnimationEffect | null, timeline?: AnimationTimeline | null): Animation; }; declare class SequenceEffect extends KeyframeEffect { @@ -118,5 +107,5 @@ interface Element { getAnimations(): Animation[]; } interface Document { - timeline: AnimationTimeline; + readonly timeline: AnimationTimeline; } diff --git a/types/webrtc/RTCPeerConnection.d.ts b/types/webrtc/RTCPeerConnection.d.ts index 210ab66ddd..4b5c1cea53 100644 --- a/types/webrtc/RTCPeerConnection.d.ts +++ b/types/webrtc/RTCPeerConnection.d.ts @@ -2,6 +2,7 @@ // Project: https://www.w3.org/TR/webrtc/ // Definitions by: Danilo Bargen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2 // // W3 Spec: https://www.w3.org/TR/webrtc/ // @@ -11,8 +12,6 @@ /// -type EventHandler = (event: Event) => void; - // https://www.w3.org/TR/webrtc/#idl-def-rtcofferansweroptions interface RTCOfferAnswerOptions { voiceActivityDetection?: boolean; // default = true @@ -28,10 +27,10 @@ interface RTCAnswerOptions extends RTCOfferAnswerOptions { } // https://www.w3.org/TR/webrtc/#idl-def-rtcpeerconnectionstate -type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed'; +// type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed'; // https://www.w3.org/TR/webrtc/#idl-def-rtcicecredentialtype -type RTCIceCredentialType = 'password' | 'token'; +// type RTCIceCredentialType = 'password' | 'token'; // https://www.w3.org/TR/webrtc/#idl-def-rtciceserver interface RTCIceServer { @@ -40,7 +39,7 @@ interface RTCIceServer { } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtcpmuxpolicy -type RTCRtcpMuxPolicy = 'negotiate' | 'require'; +// type RTCRtcpMuxPolicy = 'negotiate' | 'require'; // https://www.w3.org/TR/webrtc/#idl-def-rtciceparameters interface RTCIceParameters { @@ -49,6 +48,7 @@ interface RTCIceParameters { } // https://www.w3.org/TR/webrtc/#idl-def-rtcicetransport +type IceTransportEventHandler = ((this: RTCIceTransport, ev: Event) => any) | null; interface RTCIceTransport { //readonly role: RTCIceRole; //readonly component: RTCIceComponent; @@ -59,17 +59,18 @@ interface RTCIceTransport { getSelectedCandidatePair(): RTCIceCandidatePair | null; getLocalParameters(): RTCIceParameters | null; getRemoteParameters(): RTCIceParameters | null; - onstatechange: EventHandler; - ongatheringstatechange: EventHandler; - onselectedcandidatepairchange: EventHandler; + onstatechange: IceTransportEventHandler; + ongatheringstatechange: IceTransportEventHandler; + onselectedcandidatepairchange: IceTransportEventHandler; } // https://www.w3.org/TR/webrtc/#idl-def-rtcdtlstransport +type DtlsTransportEventHandler = ((this: RTCDtlsTransport, ev: Event) => any) | null; interface RTCDtlsTransport { readonly transport: RTCIceTransport; //readonly state: RTCDtlsTransportState; getRemoteCertificates(): ArrayBuffer[]; - onstatechange: EventHandler; + onstatechange: DtlsTransportEventHandler; } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpcodeccapability @@ -79,7 +80,7 @@ interface RTCRtpCodecCapability { // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpheaderextensioncapability interface RTCRtpHeaderExtensionCapability { - uri: string; + uri?: string; } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpcapabilities @@ -99,17 +100,17 @@ interface RTCRtpFecParameters { } // https://www.w3.org/TR/webrtc/#idl-def-rtcdtxstatus -type RTCDtxStatus = 'disabled' | 'enabled'; +// type RTCDtxStatus = 'disabled' | 'enabled'; // https://www.w3.org/TR/webrtc/#idl-def-rtcprioritytype -type RTCPriorityType = 'very-low' | 'low' | 'medium' | 'high'; +// type RTCPriorityType = 'very-low' | 'low' | 'medium' | 'high'; // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpencodingparameters interface RTCRtpEncodingParameters { //ssrc: number; //rtx: RTCRtpRtxParameters; //fec: RTCRtpFecParameters; - dtx: RTCDtxStatus; + dtx?: RTCDtxStatus; //active: boolean; //priority: RTCPriorityType; //maxBitrate: number; @@ -121,7 +122,7 @@ interface RTCRtpEncodingParameters { interface RTCRtpHeaderExtensionParameters { //uri: string; //id: number; - encrypted: boolean; + encrypted?: boolean; } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtcpparameters @@ -136,7 +137,7 @@ interface RTCRtpCodecParameters { mimeType: string; //clockRate: number; channels?: number; // default = 1 - sdpFmtpLine: string; + sdpFmtpLine?: string; } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpparameters @@ -152,9 +153,9 @@ interface RTCRtpParameters { // https://www.w3.org/TR/webrtc/#dom-rtcrtpcontributingsource interface RTCRtpContributingSource { //readonly timestamp: number; - readonly source: number; + source: number; //readonly audioLevel: number | null; - readonly voiceActivityFlag: boolean | null; + readonly voiceActivityFlag?: boolean | undefined; } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpcapabilities @@ -183,7 +184,7 @@ interface RTCRtpReceiver { } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtptransceiverdirection -type RTCRtpTransceiverDirection = 'sendrecv' | 'sendonly' | 'recvonly' | 'inactive'; +// type RTCRtpTransceiverDirection = 'sendrecv' | 'sendonly' | 'recvonly' | 'inactive'; // https://www.w3.org/TR/webrtc/#idl-def-rtcrtptransceiver interface RTCRtpTransceiver { @@ -191,7 +192,7 @@ interface RTCRtpTransceiver { readonly sender: RTCRtpSender; readonly receiver: RTCRtpReceiver; readonly stopped: boolean; - readonly direction: RTCRtpTransceiverDirection; + direction: RTCRtpTransceiverDirection; setDirection(direction: RTCRtpTransceiverDirection): void; stop(): void; setCodecPreferences(codecs: RTCRtpCodecCapability[]): void; @@ -200,8 +201,8 @@ interface RTCRtpTransceiver { // https://www.w3.org/TR/webrtc/#idl-def-rtcrtptransceiverinit interface RTCRtpTransceiverInit { direction?: RTCRtpTransceiverDirection; // default = 'sendrecv' - streams: MediaStream[]; - sendEncodings: RTCRtpEncodingParameters[]; + streams?: MediaStream[]; + sendEncodings?: RTCRtpEncodingParameters[]; } // https://www.w3.org/TR/webrtc/#dom-rtccertificate @@ -241,12 +242,13 @@ interface RTCDataChannelInit { } // https://www.w3.org/TR/webrtc/#idl-def-rtcdatachannelstate -type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed'; +// type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed'; // https://www.w3.org/TR/websockets/#dom-websocket-binarytype -type RTCBinaryType = 'blob' | 'arraybuffer'; +// type RTCBinaryType = 'blob' | 'arraybuffer'; // https://www.w3.org/TR/webrtc/#idl-def-rtcdatachannel +type DataChannelEventHandler = ((this: RTCDataChannel, ev: E) => any) | null; interface RTCDataChannel extends EventTarget { readonly label: string; readonly ordered: boolean; @@ -254,33 +256,33 @@ interface RTCDataChannel extends EventTarget { readonly maxRetransmits: number | null; readonly protocol: string; readonly negotiated: boolean; - readonly id: number; + readonly id: number | null; readonly readyState: RTCDataChannelState; readonly bufferedAmount: number; bufferedAmountLowThreshold: number; - binaryType: RTCBinaryType; + binaryType: string; close(): void; send(data: string | Blob | ArrayBuffer | ArrayBufferView): void; - onopen: EventHandler; - onmessage: (event: MessageEvent) => void; - onbufferedamountlow: EventHandler; - onerror: (event: ErrorEvent) => void; - onclose: EventHandler; + onopen: DataChannelEventHandler; + onmessage: DataChannelEventHandler; + onbufferedamountlow: DataChannelEventHandler; + onerror: DataChannelEventHandler; + onclose: DataChannelEventHandler; } // https://www.w3.org/TR/webrtc/#h-rtctrackevent interface RTCTrackEvent extends Event { readonly receiver: RTCRtpReceiver; readonly track: MediaStreamTrack; - readonly streams: MediaStream[]; + readonly streams: ReadonlyArray; readonly transceiver: RTCRtpTransceiver; } // https://www.w3.org/TR/webrtc/#h-rtcpeerconnectioniceevent interface RTCPeerConnectionIceEvent extends Event { - readonly url: string; + readonly url: string | null; } // https://www.w3.org/TR/webrtc/#h-rtcpeerconnectioniceerrorevent @@ -297,6 +299,7 @@ interface RTCDataChannelEvent { } // https://www.w3.org/TR/webrtc/#idl-def-rtcpeerconnection +type PeerConnectionEventHandler = ((this: RTCPeerConnection, ev: E) => any) | null; interface RTCPeerConnection extends EventTarget { createOffer(options?: RTCOfferOptions): Promise; createAnswer(options?: RTCAnswerOptions): Promise; @@ -320,8 +323,8 @@ interface RTCPeerConnection extends EventTarget { setConfiguration(configuration: RTCConfiguration): void; close(): void; - onicecandidateerror: (event: RTCPeerConnectionIceErrorEvent) => void; - onconnectionstatechange: EventHandler; + onicecandidateerror: PeerConnectionEventHandler; + onconnectionstatechange: PeerConnectionEventHandler; // Extension: https://www.w3.org/TR/webrtc/#h-rtcpeerconnection-interface-extensions getSenders(): RTCRtpSender[]; @@ -330,12 +333,12 @@ interface RTCPeerConnection extends EventTarget { addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender; removeTrack(sender: RTCRtpSender): void; addTransceiver(trackOrKind: MediaStreamTrack | string, init?: RTCRtpTransceiverInit): RTCRtpTransceiver; - ontrack: (event: RTCTrackEvent) => void; + ontrack: PeerConnectionEventHandler; // Extension: https://www.w3.org/TR/webrtc/#h-rtcpeerconnection-interface-extensions-1 readonly sctp: RTCSctpTransport | null; createDataChannel(label: string | null, dataChannelDict?: RTCDataChannelInit): RTCDataChannel; - ondatachannel: (event: RTCDataChannelEvent) => void; + ondatachannel: PeerConnectionEventHandler; // Extension: https://www.w3.org/TR/webrtc/#h-rtcpeerconnection-interface-extensions-2 getStats(selector?: MediaStreamTrack | null): Promise; From 398bd65886d481fdc91a49591a5b18ceab699569 Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Wed, 21 Nov 2018 14:43:15 -0500 Subject: [PATCH 040/792] Remove inaccurate deprecation warning --- types/mongodb/index.d.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 458aef1fc5..ca7b331f5b 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -45,10 +45,7 @@ export class MongoClient extends EventEmitter { static connect(uri: string, callback: MongoCallback): void; static connect(uri: string, options?: MongoClientOptions): Promise; static connect(uri: string, options: MongoClientOptions, callback: MongoCallback): void; - /** - * @deprecated - * http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#connect - */ + /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#connect */ connect(): Promise; connect(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#close */ From a57ef63d3cb13e22b83b61784a7e35e0702863dd Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Wed, 21 Nov 2018 15:21:03 -0500 Subject: [PATCH 041/792] Added missing index spec and collation document interfaces --- types/mongodb/index.d.ts | 50 ++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index ca7b331f5b..a217b0a605 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -655,9 +655,9 @@ export interface Collection { createIndex(fieldOrSpec: string | any, options?: IndexOptions): Promise; createIndex(fieldOrSpec: string | any, options: IndexOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#createIndexes and http://docs.mongodb.org/manual/reference/command/createIndexes/ */ - createIndexes(indexSpecs: Object[], callback: MongoCallback): void; - createIndexes(indexSpecs: Object[], options?: { session?: ClientSession }): Promise; - createIndexes(indexSpecs: Object[], options: { session?: ClientSession }, callback: MongoCallback): void; + createIndexes(indexSpecs: IndexSpecification[], callback: MongoCallback): void; + createIndexes(indexSpecs: IndexSpecification[], options?: { session?: ClientSession }): Promise; + createIndexes(indexSpecs: IndexSpecification[], options: { session?: ClientSession }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#deleteMany */ deleteMany(filter: FilterQuery, callback: MongoCallback): void; deleteMany(filter: FilterQuery, options?: CommonOptions): Promise; @@ -1074,7 +1074,7 @@ export interface CollectionAggregationOptions { promoteLongs?: boolean; promoteValues?: boolean; promoteBuffers?: boolean; - collation?: Object; + collation?: CollationDocument; comment?: string session?: ClientSession; @@ -1311,7 +1311,7 @@ export interface FindOneOptions { readPreference?: ReadPreference | string; partial?: boolean; maxTimeMs?: number; - collation?: Object; + collation?: CollationDocument; session?: ClientSession; } @@ -1430,7 +1430,7 @@ export class Cursor extends Readable { close(): Promise; close(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#collation */ - collation(value: Object): Cursor; + collation(value: CollationDocument): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#comment */ comment(value: string): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#count */ @@ -1729,7 +1729,7 @@ export interface ChangeStreamOptions { maxAwaitTimeMS?: number; resumeAfter?: Object; batchSize?: number; - collation?: Object; + collation?: CollationDocument; readPreference?: ReadPreference; } @@ -1780,3 +1780,39 @@ export class Logger { // Set the current log level static setLevel(level: string): void } + +/** https://docs.mongodb.com/manual/reference/collation/#collation-document-fields */ +export interface CollationDocument { + locale: string; + strength?: number; + caseLevel?: boolean; + caseFirst?: boolean; + numericOrdering?: boolean; + alternate?: string; + maxVariable?: string; + backwards?: boolean; + normalization?: boolean; + +} + +/** https://docs.mongodb.com/manual/reference/command/createIndexes/ */ +export interface IndexSpecification { + key: object; + name?: string; + background?: boolean; + unique?: boolean; + partialFilterExpression?: object; + sparse?: boolean; + expireAfterSeconds?: number; + storageEngine?: object; + weights?: object; + default_language?: string; + language_override?: string; + textIndexVersion?: number; + '2dsphereIndexVersion'?: number; + bits?: number; + min?: number; + max?: number; + bucketSize?: number; + collation?: CollationDocument; +} From 289d09cce48cbd9faf698fa59864a5aef463dbe1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 21 Nov 2018 12:41:56 -0800 Subject: [PATCH 042/792] Remove code instead of commenting it out --- types/webrtc/RTCPeerConnection.d.ts | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/types/webrtc/RTCPeerConnection.d.ts b/types/webrtc/RTCPeerConnection.d.ts index 4b5c1cea53..e5dfd79be9 100644 --- a/types/webrtc/RTCPeerConnection.d.ts +++ b/types/webrtc/RTCPeerConnection.d.ts @@ -26,21 +26,12 @@ interface RTCOfferOptions extends RTCOfferAnswerOptions { interface RTCAnswerOptions extends RTCOfferAnswerOptions { } -// https://www.w3.org/TR/webrtc/#idl-def-rtcpeerconnectionstate -// type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed'; - -// https://www.w3.org/TR/webrtc/#idl-def-rtcicecredentialtype -// type RTCIceCredentialType = 'password' | 'token'; - // https://www.w3.org/TR/webrtc/#idl-def-rtciceserver interface RTCIceServer { //urls: string | string[]; credentialType?: RTCIceCredentialType; // default = 'password' } -// https://www.w3.org/TR/webrtc/#idl-def-rtcrtcpmuxpolicy -// type RTCRtcpMuxPolicy = 'negotiate' | 'require'; - // https://www.w3.org/TR/webrtc/#idl-def-rtciceparameters interface RTCIceParameters { //usernameFragment: string; @@ -99,12 +90,6 @@ interface RTCRtpFecParameters { //ssrc: number; } -// https://www.w3.org/TR/webrtc/#idl-def-rtcdtxstatus -// type RTCDtxStatus = 'disabled' | 'enabled'; - -// https://www.w3.org/TR/webrtc/#idl-def-rtcprioritytype -// type RTCPriorityType = 'very-low' | 'low' | 'medium' | 'high'; - // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpencodingparameters interface RTCRtpEncodingParameters { //ssrc: number; @@ -183,9 +168,6 @@ interface RTCRtpReceiver { getContributingSources(): RTCRtpContributingSource[]; } -// https://www.w3.org/TR/webrtc/#idl-def-rtcrtptransceiverdirection -// type RTCRtpTransceiverDirection = 'sendrecv' | 'sendonly' | 'recvonly' | 'inactive'; - // https://www.w3.org/TR/webrtc/#idl-def-rtcrtptransceiver interface RTCRtpTransceiver { readonly mid: string | null; @@ -241,12 +223,6 @@ interface RTCDataChannelInit { id?: number; } -// https://www.w3.org/TR/webrtc/#idl-def-rtcdatachannelstate -// type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed'; - -// https://www.w3.org/TR/websockets/#dom-websocket-binarytype -// type RTCBinaryType = 'blob' | 'arraybuffer'; - // https://www.w3.org/TR/webrtc/#idl-def-rtcdatachannel type DataChannelEventHandler = ((this: RTCDataChannel, ev: E) => any) | null; interface RTCDataChannel extends EventTarget { From f6a44f54c73a0b255e7b36a1953824e518165996 Mon Sep 17 00:00:00 2001 From: IanStorm Date: Wed, 21 Nov 2018 22:04:54 +0100 Subject: [PATCH 043/792] * Added "test" for instantiating `ListStream` without `new` * Added "test" for using `write` on a `ListStream` instance --- types/list-stream/index.d.ts | 17 +++++++++++------ types/list-stream/list-stream-tests.ts | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/types/list-stream/index.d.ts b/types/list-stream/index.d.ts index 226d4c09ab..b51c9bacb0 100644 --- a/types/list-stream/index.d.ts +++ b/types/list-stream/index.d.ts @@ -7,16 +7,21 @@ import { Duplex, DuplexOptions } from "stream"; -declare namespace ListStream { +interface ListStreamMethod { + (callback?: (err: Error, data: any[]) => void): ListStream; + (options?: DuplexOptions, callback?: (err: Error, data: any[]) => void): ListStream; } -declare class ListStream extends Duplex { - constructor(callback?: (err: Error, data: any[]) => void); - constructor(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void); +interface ListStreamConstructor extends ListStreamMethod { + new(callback?: (err: Error, data: any[]) => void): ListStream; + new(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void): ListStream; - static obj(callback?: (err: Error, data: any[]) => void): ListStream; - static obj(options?: DuplexOptions, callback?: (err: Error, data: any[]) => void): ListStream; + obj: ListStreamMethod; +} +declare let ListStream: ListStreamConstructor; + +interface ListStream extends Duplex { append(chunk: any): void; duplicate(): ListStream; end(): void; diff --git a/types/list-stream/list-stream-tests.ts b/types/list-stream/list-stream-tests.ts index 4b7fc2a6ab..5f04626b31 100644 --- a/types/list-stream/list-stream-tests.ts +++ b/types/list-stream/list-stream-tests.ts @@ -4,6 +4,20 @@ let chunk: any = "chunk"; let listStream: ListStream; let num = 1; +listStream = ListStream((err: Error, data: any[]) => { + if (err) { throw err; } + console.log(data.length); + for (const date of data) { + console.log(date); + } +}); +listStream = ListStream({ objectMode: true }, (err: Error, data: any[]) => { + if (err) { throw err; } + console.log(data.length); + for (const date of data) { + console.log(date); + } +}); listStream = new ListStream((err: Error, data: any[]) => { if (err) { throw err; } console.log(data.length); @@ -26,6 +40,9 @@ listStream = ListStream.obj((err: Error, data: any[]) => { } }); +listStream = ListStream.obj(); +listStream.write({ key: "value" }); + listStream.append(chunk); listStream = listStream.duplicate(); From 60d9095e61563415668e240eadfa8d2469548bf7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 21 Nov 2018 13:27:18 -0800 Subject: [PATCH 044/792] Seems like webrtc was added in 3.0 --- types/webrtc/RTCPeerConnection.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/webrtc/RTCPeerConnection.d.ts b/types/webrtc/RTCPeerConnection.d.ts index e5dfd79be9..9dc2faae12 100644 --- a/types/webrtc/RTCPeerConnection.d.ts +++ b/types/webrtc/RTCPeerConnection.d.ts @@ -2,7 +2,7 @@ // Project: https://www.w3.org/TR/webrtc/ // Definitions by: Danilo Bargen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.2 +// TypeScript Version: 3.0 // // W3 Spec: https://www.w3.org/TR/webrtc/ // @@ -140,7 +140,7 @@ interface RTCRtpContributingSource { //readonly timestamp: number; source: number; //readonly audioLevel: number | null; - readonly voiceActivityFlag?: boolean | undefined; + readonly voiceActivityFlag?: boolean; } // https://www.w3.org/TR/webrtc/#idl-def-rtcrtpcapabilities From 089442e1a9440bf89474edf2d81d13c3bd96226e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 21 Nov 2018 13:33:21 -0800 Subject: [PATCH 045/792] Put version header in index.d.ts --- types/webrtc/RTCPeerConnection.d.ts | 1 - types/webrtc/index.d.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/types/webrtc/RTCPeerConnection.d.ts b/types/webrtc/RTCPeerConnection.d.ts index 9dc2faae12..3df7999212 100644 --- a/types/webrtc/RTCPeerConnection.d.ts +++ b/types/webrtc/RTCPeerConnection.d.ts @@ -2,7 +2,6 @@ // Project: https://www.w3.org/TR/webrtc/ // Definitions by: Danilo Bargen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.0 // // W3 Spec: https://www.w3.org/TR/webrtc/ // diff --git a/types/webrtc/index.d.ts b/types/webrtc/index.d.ts index 4a16860637..e087a03f4e 100644 --- a/types/webrtc/index.d.ts +++ b/types/webrtc/index.d.ts @@ -2,7 +2,7 @@ // Project: https://webrtc.org/ // Definitions by: Toshiya Nakakura // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// /// From 588718bc304d4b577457032f8348decfce16b5cb Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 21 Nov 2018 13:38:02 -0800 Subject: [PATCH 046/792] Update w3c-image-capture's dependencies too --- types/w3c-image-capture/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/w3c-image-capture/index.d.ts b/types/w3c-image-capture/index.d.ts index 8f04fad534..24a7d917c4 100644 --- a/types/w3c-image-capture/index.d.ts +++ b/types/w3c-image-capture/index.d.ts @@ -2,7 +2,7 @@ // Project: https://www.w3.org/TR/image-capture/ // Definitions by: Cosium // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// From a72081e2b5cdc37d2e47acec4b1526250093575a Mon Sep 17 00:00:00 2001 From: Peter Safranek Date: Wed, 21 Nov 2018 15:07:50 -0800 Subject: [PATCH 047/792] [gulp-json-validator] Introduce typings for gulp-json-validator --- .../gulp-json-validator-tests.ts | 6 +++++ types/gulp-json-validator/index.d.ts | 14 +++++++++++ types/gulp-json-validator/tsconfig.json | 23 +++++++++++++++++++ types/gulp-json-validator/tslint.json | 6 +++++ 4 files changed, 49 insertions(+) create mode 100644 types/gulp-json-validator/gulp-json-validator-tests.ts create mode 100644 types/gulp-json-validator/index.d.ts create mode 100644 types/gulp-json-validator/tsconfig.json create mode 100644 types/gulp-json-validator/tslint.json diff --git a/types/gulp-json-validator/gulp-json-validator-tests.ts b/types/gulp-json-validator/gulp-json-validator-tests.ts new file mode 100644 index 0000000000..74a00f03da --- /dev/null +++ b/types/gulp-json-validator/gulp-json-validator-tests.ts @@ -0,0 +1,6 @@ +import gulpJsonValidator = require("gulp-json-validator"); + +gulpJsonValidator(); // $ExpectType ReadWriteStream +gulpJsonValidator({}); // $ExpectType ReadWriteStream +gulpJsonValidator({ allowDuplicatedKeys: true }); // $ExpectType ReadWriteStream +gulpJsonValidator({ allowDuplicatedKeys: false }); // $ExpectType ReadWriteStream diff --git a/types/gulp-json-validator/index.d.ts b/types/gulp-json-validator/index.d.ts new file mode 100644 index 0000000000..26e31d8b43 --- /dev/null +++ b/types/gulp-json-validator/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for gulp-json-validator 1.2 +// Project: https://github.com/jackyjieliu/gulp-json-validator +// Definitions by: Peter Safranek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +interface GulpJsonValidatorOptions { + allowDuplicatedKeys?: boolean; +} + +declare function gulpJsonValidator(option?: GulpJsonValidatorOptions): NodeJS.ReadWriteStream; + +export = gulpJsonValidator; diff --git a/types/gulp-json-validator/tsconfig.json b/types/gulp-json-validator/tsconfig.json new file mode 100644 index 0000000000..76ee50c184 --- /dev/null +++ b/types/gulp-json-validator/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gulp-json-validator-tests.ts" + ] +} diff --git a/types/gulp-json-validator/tslint.json b/types/gulp-json-validator/tslint.json new file mode 100644 index 0000000000..702f9354fc --- /dev/null +++ b/types/gulp-json-validator/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "file-name-casing": false + } +} From 4d312320c106bc1a3af3fb1cf88bd0fd11ad3757 Mon Sep 17 00:00:00 2001 From: danford Date: Thu, 22 Nov 2018 11:13:10 +1100 Subject: [PATCH 048/792] react-css-collapse --- types/react-css-collapse/index.d.ts | 18 +++++ .../react-css-collapse-tests.tsx | 14 ++++ types/react-css-collapse/tsconfig.json | 25 ++++++ types/react-css-collapse/tslint.json | 79 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 types/react-css-collapse/index.d.ts create mode 100644 types/react-css-collapse/react-css-collapse-tests.tsx create mode 100644 types/react-css-collapse/tsconfig.json create mode 100644 types/react-css-collapse/tslint.json diff --git a/types/react-css-collapse/index.d.ts b/types/react-css-collapse/index.d.ts new file mode 100644 index 0000000000..aa17200367 --- /dev/null +++ b/types/react-css-collapse/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for react-css-collapse 3.6.0 +// Project: https://github.com/SparebankenVest/react-css-collapse; +// Definitions by: Daniel Ford +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +declare module 'react-css-collapse' { + interface Props { + isOpen: boolean; + className?: string | null; + onRest?: () => void; + transition?: string | null; + } + class Collapse extends React.Component { + public render(): React.ReactElement; + } + export default Collapse; +} diff --git a/types/react-css-collapse/react-css-collapse-tests.tsx b/types/react-css-collapse/react-css-collapse-tests.tsx new file mode 100644 index 0000000000..3b699b530d --- /dev/null +++ b/types/react-css-collapse/react-css-collapse-tests.tsx @@ -0,0 +1,14 @@ +import * as React from "react"; +import { SFC } from "react"; +import { render } from "react-dom"; +import Collapse from "react-css-collapse"; + +const TestOpen: SFC = () => ( + +
+ i am open +
+
+); + +render(, document.getElementById("main")); diff --git a/types/react-css-collapse/tsconfig.json b/types/react-css-collapse/tsconfig.json new file mode 100644 index 0000000000..4af49b9769 --- /dev/null +++ b/types/react-css-collapse/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-css-collapse-tests.tsx" + ] +} diff --git a/types/react-css-collapse/tslint.json b/types/react-css-collapse/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/react-css-collapse/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} From 809fc1d291a42de5da96d6fa03796452bcde1c82 Mon Sep 17 00:00:00 2001 From: feinoujc Date: Wed, 21 Nov 2018 21:33:29 -0500 Subject: [PATCH 049/792] add graphql-fields typings --- types/graphql-fields/graphql-fields-tests.ts | 8 +++++++ types/graphql-fields/index.d.ts | 18 +++++++++++++++ types/graphql-fields/tsconfig.json | 24 ++++++++++++++++++++ types/graphql-fields/tslint.json | 1 + 4 files changed, 51 insertions(+) create mode 100644 types/graphql-fields/graphql-fields-tests.ts create mode 100644 types/graphql-fields/index.d.ts create mode 100644 types/graphql-fields/tsconfig.json create mode 100644 types/graphql-fields/tslint.json diff --git a/types/graphql-fields/graphql-fields-tests.ts b/types/graphql-fields/graphql-fields-tests.ts new file mode 100644 index 0000000000..811fe25ab2 --- /dev/null +++ b/types/graphql-fields/graphql-fields-tests.ts @@ -0,0 +1,8 @@ +import { GraphQLResolveInfo } from 'graphql'; +import graphqlFields = require('graphql-fields'); + +const info = ({} as any) as GraphQLResolveInfo; + +const fieldsWithSubFieldsArgs = graphqlFields(info, {}, { processArguments: true }); +const fieldsWithoutTypeName = graphqlFields(info, {}, { excludedFields: ['__typename'] }); +graphqlFields(info); diff --git a/types/graphql-fields/index.d.ts b/types/graphql-fields/index.d.ts new file mode 100644 index 0000000000..19e7f21dc4 --- /dev/null +++ b/types/graphql-fields/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for graphql-fields 1.3 +// Project: https://github.com/robrichard/graphql-fields#readme +// Definitions by: feinoujc +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +import { GraphQLResolveInfo } from 'graphql'; + +declare function graphqlFields(info: GraphQLResolveInfo, obj?: object, opts?: graphqlFields.Options): any; + +declare namespace graphqlFields { + interface Options { + processArguments?: boolean; + excludedFields?: string[]; + } +} + +export = graphqlFields; diff --git a/types/graphql-fields/tsconfig.json b/types/graphql-fields/tsconfig.json new file mode 100644 index 0000000000..826e200b41 --- /dev/null +++ b/types/graphql-fields/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "esnext.asynciterable" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "graphql-fields-tests.ts" + ] +} diff --git a/types/graphql-fields/tslint.json b/types/graphql-fields/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/graphql-fields/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 4af88ab850423bf48f34057d0009d0dc786e0d23 Mon Sep 17 00:00:00 2001 From: Ben Frengley Date: Thu, 22 Nov 2018 16:24:15 +1300 Subject: [PATCH 050/792] [@types/mapbox-gl] Fix source type in source events + indentation fix --- types/mapbox-gl/index.d.ts | 2 +- types/mapbox-gl/mapbox-gl-tests.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 91fb68cd96..f3389876b9 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -1071,7 +1071,7 @@ declare namespace mapboxgl { export interface MapSourceDataEvent extends MapboxEvent { dataType: 'source'; isSourceLoaded: boolean; - source: Style; + source: Source; sourceId: string; sourceDataType: 'metadata' | 'content'; tile: any; diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts index 422b255900..d119c76bd5 100644 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ b/types/mapbox-gl/mapbox-gl-tests.ts @@ -465,10 +465,10 @@ expectType(mapboxgl.Point.convert(pointlike)); expectType((url: string) => ({ url })); expectType((url: string, resourceType: mapboxgl.ResourceType) => ({ - url, - credentials: 'same-origin', - headers: { 'Accept-Encoding': 'compress' }, - method: 'POST', + url, + credentials: 'same-origin', + headers: { 'Accept-Encoding': 'compress' }, + method: 'POST', collectResourceTiming: true, })); From 7120224aac33e95d45696e486351f0ca23f9e1e9 Mon Sep 17 00:00:00 2001 From: Sammyt Date: Wed, 21 Nov 2018 18:02:32 +0100 Subject: [PATCH 051/792] Add scrollablePlotArea options in ChartOptions --- types/highcharts/index.d.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/highcharts/index.d.ts b/types/highcharts/index.d.ts index 167d6532d3..a2d3c5b44f 100644 --- a/types/highcharts/index.d.ts +++ b/types/highcharts/index.d.ts @@ -2232,6 +2232,10 @@ declare namespace Highcharts { * The button that appears after a selection zoom, allowing the user to reset zoom. */ resetZoomButton?: ChartResetZoomButton; + /** + * Options for a scrollable plot area + */ + scrollablePlotArea?: ScrollablePropArea; /** * The background color of the marker square when selecting (zooming in on) an area of the chart. * @default 'rgba(69,114,167,0.25)' @@ -3495,6 +3499,11 @@ declare namespace Highcharts { update(options: TitleOptions): void; } + interface ScrollablePropArea { + minWidth?: number; + scrollPositionX?: number; + } + /** * Under which conditions the rule applies. */ From 75dc5a9ca427435bf3d0b79a4fd6910f6a1b7b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=BCnch?= Date: Thu, 22 Nov 2018 09:33:58 +0100 Subject: [PATCH 052/792] add parameter [decapitalize=false] to camelize https://github.com/epeli/underscore.string#camelizestring-decapitalizefalse--string --- types/underscore.string/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/underscore.string/index.d.ts b/types/underscore.string/index.d.ts index 2d067679d5..eb0774b49a 100644 --- a/types/underscore.string/index.d.ts +++ b/types/underscore.string/index.d.ts @@ -207,7 +207,7 @@ declare module 'underscore' { * ('-moz-transform') => 'MozTransform' * @param str */ - camelize(str: string): string; + camelize(str: string, decapitalize?: boolean): string; /** * Converts a camelized or dasherized string into an underscored one. From b4a016ba645a65f8e16dcefdfcb260d1ce2e238d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=BCnch?= Date: Thu, 22 Nov 2018 09:44:42 +0100 Subject: [PATCH 053/792] [@types/underscore.string] reflect change within test _.camelize('-moz-transform'); _.camelize('-moz-transform', true); --- types/underscore.string/underscore.string-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/underscore.string/underscore.string-tests.ts b/types/underscore.string/underscore.string-tests.ts index 545f6362d6..5b827cd880 100644 --- a/types/underscore.string/underscore.string-tests.ts +++ b/types/underscore.string/underscore.string-tests.ts @@ -52,6 +52,7 @@ _.succ('A'); _.titleize('my name is epeli'); _.camelize('-moz-transform'); +_.camelize('-moz-transform', true); _.classify('some_class_name'); From 6922a35f4b9905b7a75a94859ffab134565a6378 Mon Sep 17 00:00:00 2001 From: Jussi Kinnula Date: Thu, 22 Nov 2018 10:25:50 +0200 Subject: [PATCH 054/792] Change gl-react subpackages callback props & gl-react Node "uniforms" prop optional & add tests for subpackages --- types/gl-react-dom/GLViewDOM.d.ts | 8 +++--- types/gl-react-dom/gl-react-dom-tests.tsx | 27 +++++++++++++++++++ types/gl-react-dom/tsconfig.json | 3 ++- types/gl-react-expo/GLViewNative.d.ts | 2 +- types/gl-react-expo/gl-react-expo-tests.tsx | 27 +++++++++++++++++++ types/gl-react-expo/tsconfig.json | 3 ++- types/gl-react-headless/GLViewHeadless.d.ts | 8 +++--- .../gl-react-headless-tests.tsx | 27 +++++++++++++++++++ types/gl-react-headless/tsconfig.json | 3 ++- types/gl-react-native/GLViewNative.d.ts | 4 +-- .../gl-react-native/gl-react-native-tests.tsx | 27 +++++++++++++++++++ types/gl-react-native/tsconfig.json | 3 ++- types/gl-react/index.d.ts | 2 +- 13 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 types/gl-react-dom/gl-react-dom-tests.tsx create mode 100644 types/gl-react-expo/gl-react-expo-tests.tsx create mode 100644 types/gl-react-headless/gl-react-headless-tests.tsx create mode 100644 types/gl-react-native/gl-react-native-tests.tsx diff --git a/types/gl-react-dom/GLViewDOM.d.ts b/types/gl-react-dom/GLViewDOM.d.ts index 8450a16a00..5ceef51ec8 100644 --- a/types/gl-react-dom/GLViewDOM.d.ts +++ b/types/gl-react-dom/GLViewDOM.d.ts @@ -4,10 +4,10 @@ export type SupportedImage = 'image/png' | 'image/jpeg' | 'image/bmp' | 'image/w export type ValidQuality = 0.0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1.0; export interface GLViewDOMProps { - onContextCreate: (gl: WebGLRenderingContext) => void; - onContextFailure: (e: Error) => void; - onContextLost: () => void; - onContextRestored: (gl: WebGLRenderingContext) => void; + onContextCreate?: (gl: WebGLRenderingContext) => void; + onContextFailure?: (e: Error) => void; + onContextLost?: () => void; + onContextRestored?: (gl: WebGLRenderingContext) => void; webglContextAttributes?: WebGLContextAttributes; pixelRatio?: number; width: number; diff --git a/types/gl-react-dom/gl-react-dom-tests.tsx b/types/gl-react-dom/gl-react-dom-tests.tsx new file mode 100644 index 0000000000..6d3852a156 --- /dev/null +++ b/types/gl-react-dom/gl-react-dom-tests.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Surface } from 'gl-react-dom'; +import { Shaders, GLSL, Node } from 'gl-react'; + +const shaders = Shaders.create({ + Test: { + frag: GLSL` + precision highp float; + varying vec2 uv; + void main() { + gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0); + }` + } +}); + +const App = () => ( +
+ + + +
+); + +const element = document.createElement('div'); +document.body.appendChild(element); +ReactDOM.render(, element); diff --git a/types/gl-react-dom/tsconfig.json b/types/gl-react-dom/tsconfig.json index 9c4d38ca44..49a1ee91ff 100644 --- a/types/gl-react-dom/tsconfig.json +++ b/types/gl-react-dom/tsconfig.json @@ -1,6 +1,7 @@ { "files": [ - "index.d.ts" + "index.d.ts", + "gl-react-dom-tests.tsx" ], "compilerOptions": { "module": "commonjs", diff --git a/types/gl-react-expo/GLViewNative.d.ts b/types/gl-react-expo/GLViewNative.d.ts index 4f0270dd68..5320ccaaa2 100644 --- a/types/gl-react-expo/GLViewNative.d.ts +++ b/types/gl-react-expo/GLViewNative.d.ts @@ -3,7 +3,7 @@ import * as React from 'react'; // import { GLView as EXGLView } from 'expo'; export interface GLViewNativeProps { - onContextCreate: (gl: WebGLRenderingContext) => void; + onContextCreate?: (gl: WebGLRenderingContext) => void; style?: any; children?: any; } diff --git a/types/gl-react-expo/gl-react-expo-tests.tsx b/types/gl-react-expo/gl-react-expo-tests.tsx new file mode 100644 index 0000000000..2eb1fee9a9 --- /dev/null +++ b/types/gl-react-expo/gl-react-expo-tests.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Surface } from 'gl-react-expo'; +import { Shaders, GLSL, Node } from 'gl-react'; + +const shaders = Shaders.create({ + Test: { + frag: GLSL` + precision highp float; + varying vec2 uv; + void main() { + gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0); + }` + } +}); + +const App = () => ( +
+ + + +
+); + +const element = document.createElement('div'); +document.body.appendChild(element); +ReactDOM.render(, element); diff --git a/types/gl-react-expo/tsconfig.json b/types/gl-react-expo/tsconfig.json index 9c4d38ca44..95487128f4 100644 --- a/types/gl-react-expo/tsconfig.json +++ b/types/gl-react-expo/tsconfig.json @@ -1,6 +1,7 @@ { "files": [ - "index.d.ts" + "index.d.ts", + "gl-react-expo-tests.tsx" ], "compilerOptions": { "module": "commonjs", diff --git a/types/gl-react-headless/GLViewHeadless.d.ts b/types/gl-react-headless/GLViewHeadless.d.ts index a94c1f9769..9b90b25958 100644 --- a/types/gl-react-headless/GLViewHeadless.d.ts +++ b/types/gl-react-headless/GLViewHeadless.d.ts @@ -1,10 +1,10 @@ import * as React from 'react'; export interface GLViewHeadlessProps { - onContextCreate: (gl: WebGLRenderingContext) => void; - onContextFailure: (e: Error) => void; - onContextLost: () => void; - onContextRestored: (gl: WebGLRenderingContext) => void; + onContextCreate?: (gl: WebGLRenderingContext) => void; + onContextFailure?: (e: Error) => void; + onContextLost?: () => void; + onContextRestored?: (gl: WebGLRenderingContext) => void; webglContextAttributes?: WebGLContextAttributes; pixelRatio?: number; width: number; diff --git a/types/gl-react-headless/gl-react-headless-tests.tsx b/types/gl-react-headless/gl-react-headless-tests.tsx new file mode 100644 index 0000000000..58f0cbc13b --- /dev/null +++ b/types/gl-react-headless/gl-react-headless-tests.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Surface } from 'gl-react-headless'; +import { Shaders, GLSL, Node } from 'gl-react'; + +const shaders = Shaders.create({ + Test: { + frag: GLSL` + precision highp float; + varying vec2 uv; + void main() { + gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0); + }` + } +}); + +const App = () => ( +
+ + + +
+); + +const element = document.createElement('div'); +document.body.appendChild(element); +ReactDOM.render(, element); diff --git a/types/gl-react-headless/tsconfig.json b/types/gl-react-headless/tsconfig.json index 9c4d38ca44..8a7f2a4b22 100644 --- a/types/gl-react-headless/tsconfig.json +++ b/types/gl-react-headless/tsconfig.json @@ -1,6 +1,7 @@ { "files": [ - "index.d.ts" + "index.d.ts", + "gl-react-headless-tests.tsx" ], "compilerOptions": { "module": "commonjs", diff --git a/types/gl-react-native/GLViewNative.d.ts b/types/gl-react-native/GLViewNative.d.ts index 0a780d3aa7..b4a4c75bc1 100644 --- a/types/gl-react-native/GLViewNative.d.ts +++ b/types/gl-react-native/GLViewNative.d.ts @@ -1,8 +1,8 @@ import * as React from 'react'; export interface GLViewNativeProps { - onContextCreate: (gl: WebGLRenderingContext) => void; - onContextFailure: (e: Error) => void; + onContextCreate?: (gl: WebGLRenderingContext) => void; + onContextFailure?: (e: Error) => void; style?: any; children?: any; } diff --git a/types/gl-react-native/gl-react-native-tests.tsx b/types/gl-react-native/gl-react-native-tests.tsx new file mode 100644 index 0000000000..f74c9dc926 --- /dev/null +++ b/types/gl-react-native/gl-react-native-tests.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Surface } from 'gl-react-native'; +import { Shaders, GLSL, Node } from 'gl-react'; + +const shaders = Shaders.create({ + Test: { + frag: GLSL` + precision highp float; + varying vec2 uv; + void main() { + gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0); + }` + } +}); + +const App = () => ( +
+ + + +
+); + +const element = document.createElement('div'); +document.body.appendChild(element); +ReactDOM.render(, element); diff --git a/types/gl-react-native/tsconfig.json b/types/gl-react-native/tsconfig.json index 9c4d38ca44..0ffab2bab3 100644 --- a/types/gl-react-native/tsconfig.json +++ b/types/gl-react-native/tsconfig.json @@ -1,6 +1,7 @@ { "files": [ - "index.d.ts" + "index.d.ts", + "gl-react-native-tests.tsx" ], "compilerOptions": { "module": "commonjs", diff --git a/types/gl-react/index.d.ts b/types/gl-react/index.d.ts index e1332fd964..84b82ddd2d 100644 --- a/types/gl-react/index.d.ts +++ b/types/gl-react/index.d.ts @@ -124,7 +124,7 @@ export interface Framebuffer { export interface NodeProps { shader: ShaderIdentifier | ShaderDefinition; uniformsOptions?: any; - uniforms: { [key: string]: any }; + uniforms?: { [key: string]: any }; ignoreUnusedUniforms?: string[] | boolean; sync?: boolean; width?: number; From 860b409ed936cf7e1dce27a6f9e000cae751e82f Mon Sep 17 00:00:00 2001 From: Adam <23192421+shenphen@users.noreply.github.com> Date: Thu, 22 Nov 2018 15:51:55 +0100 Subject: [PATCH 055/792] Update index.d.ts with replace function overload Change due to the documentation of cropperjs (https://www.npmjs.com/package/cropperjs#replaceurl-hassamesize). --- types/cropperjs/index.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/cropperjs/index.d.ts b/types/cropperjs/index.d.ts index 30556e11fc..6e48bdae49 100644 --- a/types/cropperjs/index.d.ts +++ b/types/cropperjs/index.d.ts @@ -428,6 +428,13 @@ declare class cropperjs { * @param url A new image url */ replace(url: string): void; + + /** + * Replace the image's src and rebuild the cropper. If the new image has the same size with the old one, then it will not rebuilt the cropper and only update the urls of all related images. This can be used for applying filters. + * @param url A new image url + * @param hasSameSize (Default: false) + */ + replace(url: string, hasSameSize: boolean): void; /** * Enable (unfreeze) the cropper. From 5d4421790f435864c13dde0750333c6818de7db4 Mon Sep 17 00:00:00 2001 From: Alex Deas Date: Thu, 22 Nov 2018 16:30:31 +0000 Subject: [PATCH 056/792] Allow type parameters for cond --- types/ramda/index.d.ts | 2 +- types/ramda/ramda-tests.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index a3bc51c8ca..77dcdb05a0 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -776,7 +776,7 @@ declare namespace R { * point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates * matches, fn returns undefined. */ - cond(fns: ReadonlyArray<[Pred, (...a: any[]) => any]>): (...a: any[]) => any; + cond(fns: ReadonlyArray<[SafePred, (a: A) => B]>): (a: A) => B; /** * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 2f68808d17..61f09c1f40 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1306,14 +1306,19 @@ type Pair = KeyValuePair; }; () => { - const fn = R.cond([ - [R.equals(0), R.always("water freezes at 0Β°C")], - [R.equals(100), R.always("water boils at 100Β°C")], - [R.T, (temp: number) => `nothing special happens at ${temp}Β°C`] + const f = R.cond([ + [x => x === 0, () => "a"], + [() => true, () => "b"], ]); - const a: string = fn(0); // => 'water freezes at 0Β°C' - const b: string = fn(50); // => 'nothing special happens at 50Β°C' - const c: string = fn(100); // => 'water boils at 100Β°C' + f(0); // $ExpectType string + f(""); // $ExpectError + + const g = R.cond([ + [x => x === 0, () => "a"], + [() => true, () => "b"], + ]); + g(0); + g(""); }; () => { From bd6515d5871238514dab001bcf0c062f0f25d721 Mon Sep 17 00:00:00 2001 From: TeamworkGuy2 Date: Thu, 22 Nov 2018 16:34:26 +0000 Subject: [PATCH 057/792] [cached-path-relative] Add cached-path-relative@1.0.2 definition --- .../cached-path-relative-tests.ts | 7 ++++++ types/cached-path-relative/index.d.ts | 8 +++++++ types/cached-path-relative/tsconfig.json | 23 +++++++++++++++++++ types/cached-path-relative/tslint.json | 1 + 4 files changed, 39 insertions(+) create mode 100644 types/cached-path-relative/cached-path-relative-tests.ts create mode 100644 types/cached-path-relative/index.d.ts create mode 100644 types/cached-path-relative/tsconfig.json create mode 100644 types/cached-path-relative/tslint.json diff --git a/types/cached-path-relative/cached-path-relative-tests.ts b/types/cached-path-relative/cached-path-relative-tests.ts new file mode 100644 index 0000000000..22e6af97df --- /dev/null +++ b/types/cached-path-relative/cached-path-relative-tests.ts @@ -0,0 +1,7 @@ +import cachedPathRelative = require("cached-path-relative"); + +function browserifyTest() { + const file = "file.txt"; + const m1: string = cachedPathRelative("./", file).replace(/\\/g, '/'); + return m1; +} diff --git a/types/cached-path-relative/index.d.ts b/types/cached-path-relative/index.d.ts new file mode 100644 index 0000000000..56076870bc --- /dev/null +++ b/types/cached-path-relative/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for cached-path-relative 1.0 +// Project: https://github.com/ashaffer/cached-path-relative +// Definitions by: TeamworkGuy2 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function cachedPathRelative(from: string, to: string): string; + +export = cachedPathRelative; diff --git a/types/cached-path-relative/tsconfig.json b/types/cached-path-relative/tsconfig.json new file mode 100644 index 0000000000..e69970c325 --- /dev/null +++ b/types/cached-path-relative/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cached-path-relative-tests.ts" + ] +} \ No newline at end of file diff --git a/types/cached-path-relative/tslint.json b/types/cached-path-relative/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cached-path-relative/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From a133ea37430313b85c65bbc775ba909c58e40a30 Mon Sep 17 00:00:00 2001 From: Markus Lasermann Date: Thu, 22 Nov 2018 17:56:50 +0100 Subject: [PATCH 058/792] add types for https://github.com/zesik/react-splitter-layout --- types/react-splitter-layout/index.d.ts | 100 ++++++++++++++++++ .../react-splitter-layout-tests.tsx | 17 +++ types/react-splitter-layout/tsconfig.json | 25 +++++ types/react-splitter-layout/tslint.json | 1 + 4 files changed, 143 insertions(+) create mode 100644 types/react-splitter-layout/index.d.ts create mode 100644 types/react-splitter-layout/react-splitter-layout-tests.tsx create mode 100644 types/react-splitter-layout/tsconfig.json create mode 100644 types/react-splitter-layout/tslint.json diff --git a/types/react-splitter-layout/index.d.ts b/types/react-splitter-layout/index.d.ts new file mode 100644 index 0000000000..ec25b5fe1a --- /dev/null +++ b/types/react-splitter-layout/index.d.ts @@ -0,0 +1,100 @@ +// Type definitions for react-splitter-layout v3.0.1 +// Project: https://github.com/zesik/react-splitter-layout#readme +// Definitions by: Markus Lasermann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1.6 + +import * as React from "react"; + +export default SplitterLayout; + +declare class SplitterLayout extends React.PureComponent { +} + +type TPrimaryIndex = 0|1; + +export interface SplitterLayoutProps { + /** + * Custom CSS class name applied to the layout div. + * You can use this to customize layout style. + * Refers to the original stylesheet to see what you can customize. + */ + customClassName?: string; + + /** + * Determine whether the layout should be a horizontal split or a vertical split. + * + * @default false + */ + vertical?: boolean; + + /** + * Determine whether the width of each pane should be calculated in percentage or by pixels. + * The default value is false, which means width is calculated in pixels. + * + * @default false + */ + percentage?: boolean; + + /** + * Index of the primary pane. + * Since SplitterLayout supports at most 2 children, only 0 or 1 is allowed. + * + * A primary pane is used to show users primary content, while a secondary pane is the other pane. + * When window size changes and percentage is set to false, primary pane's size is flexible + * and secondary pane's size is kept unchanged. However, when the window size is not enough + * for showing both minimal primary pane and minimal secondary pane, + * the primary pane's size is served first. + * + * @default 0 + */ + primaryIndex?: TPrimaryIndex; + + /** + * Minimal size of primary pane. + * When percentage is set to false, this value is pixel size (25 means 25px). + * When percentage is set to true, this value is percentage (25 means 25%). + * + * @default 0 + */ + primaryMinSize?: number; + + /** + * Minimal size of secondary pane. + */ + secondaryMinSize?: number; + + /** + * Initial size of secondary pane when page loads. + * If this prop is not defined, SplitterLayout tries to split the layout with equal sizes. + * (Note: equal size may not apply when there are nested layouts.) + * + * @default undefined + */ + secondaryInitialSize?: number; + + /** + * Called when dragging is started. + * + * No parameter will be passed to event handlers. + */ + onDragStart?: () => void; + + /** + * Called when dragging finishes. + * + * No parameter will be passed to event handlers. + */ + onDragEnd?: () => void; + + /** + * Called when the size of secondary pane is changed. + * + * Event handlers will be passed with a single parameter of number type representing + * new size of secondary pane. + * When percentage is set to false, the value is in pixel size. + * When percentage is set to true, the value is in percentage. + */ + onSecondaryPaneSizeChange?: (value: number) => void; +} + diff --git a/types/react-splitter-layout/react-splitter-layout-tests.tsx b/types/react-splitter-layout/react-splitter-layout-tests.tsx new file mode 100644 index 0000000000..1f97db7077 --- /dev/null +++ b/types/react-splitter-layout/react-splitter-layout-tests.tsx @@ -0,0 +1,17 @@ +import * as React from "react"; +import SplitterLayout, {SplitterLayoutProps} from "react-splitter-layout"; + +export class SplitterLayoutTest extends React.PureComponent<{}> { + render(): JSX.Element { + const props: SplitterLayoutProps = { + percentage: true, + secondaryInitialSize: 30, + }; + return ( + +
1st
+
2nd
+
+ ); + } +} diff --git a/types/react-splitter-layout/tsconfig.json b/types/react-splitter-layout/tsconfig.json new file mode 100644 index 0000000000..e268261ea1 --- /dev/null +++ b/types/react-splitter-layout/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "jsx": "react", + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-splitter-layout-tests.tsx" + ] +} diff --git a/types/react-splitter-layout/tslint.json b/types/react-splitter-layout/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-splitter-layout/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 756349c67c53c76888b575abe1c7e545378b72fe Mon Sep 17 00:00:00 2001 From: Boris Sergeyev Date: Thu, 22 Nov 2018 21:43:51 +0100 Subject: [PATCH 059/792] [react-redux] fixed mistreating of action thunk creator parameters --- types/react-redux/index.d.ts | 11 +++++++--- types/react-redux/react-redux-tests.tsx | 27 ++++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index 2f919581f4..1cccae6d01 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -13,7 +13,7 @@ // Anatoli Papirovski // Boris Sergeyev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 // Known Issue: // There is a known issue in TypeScript, which doesn't allow decorators to change the signature of the classes @@ -112,9 +112,14 @@ export type InferableComponentEnhancerWithProps = export type InferableComponentEnhancer = InferableComponentEnhancerWithProps; +export type WrappedThunkActionCreator any> = + TActionCreator extends (...args: infer TParams) => (...args: any[]) => infer TReturn + ? (...args: TParams) => TReturn + : TActionCreator; + export type HandleThunkActionCreator = - TActionCreator extends (...args: any[]) => (...args: any[]) => any - ? ReturnType + TActionCreator extends (...args: any[]) => any + ? WrappedThunkActionCreator : TActionCreator; // redux-thunk middleware returns thunk's return value from dispatch call diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index aff8515e87..f47683047e 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -102,20 +102,27 @@ function MapDispatch() { } function MapDispatchWithThunkActionCreators() { - class TestComponent extends React.Component<{ - foo: string, - onClick(): void, - thunkAction(): Promise - }> {} - - const mapDispatchToProps = () => ({ - onClick: () => {}, - thunkAction: () => async () => {} + const simpleAction = (payload: boolean) => ({ + type: 'SIMPLE_ACTION', + payload, }); + const thunkAction = (param1: number, param2: string) => ( + async (dispatch: Dispatch, { foo }: OwnProps) => { + return foo; + } + ); + interface OwnProps { + foo: string; + } + interface TestComponentProps extends OwnProps { + simpleAction: typeof simpleAction; + thunkAction(param1: number, param2: string): Promise; + } + class TestComponent extends React.Component {} const Test = connect( null, - mapDispatchToProps, + ({ simpleAction, thunkAction }), )(TestComponent); const verify = ; From 35d989dce077cdd42be9943a53895eeebf569fb8 Mon Sep 17 00:00:00 2001 From: Boris Sergeyev Date: Thu, 22 Nov 2018 22:16:23 +0100 Subject: [PATCH 060/792] [react-redux] bumped TS versions of packages dependent on react-redux --- types/mirrorx/index.d.ts | 2 +- types/next-redux-saga/index.d.ts | 2 +- types/next-redux-wrapper/index.d.ts | 2 +- types/react-intl-redux/index.d.ts | 2 +- types/react-lifecycle-component/index.d.ts | 2 +- types/react-redux-toastr/index.d.ts | 2 +- types/react-router-redux/index.d.ts | 2 +- types/redux-auth-wrapper/index.d.ts | 2 +- types/redux-devtools/index.d.ts | 2 +- types/redux-form/index.d.ts | 2 +- types/redux-form/v6/index.d.ts | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/types/mirrorx/index.d.ts b/types/mirrorx/index.d.ts index 443712c325..e2fa0ee465 100644 --- a/types/mirrorx/index.d.ts +++ b/types/mirrorx/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/mirrorjs/mirror // Definitions by: Aaronphy // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import * as H from 'history'; diff --git a/types/next-redux-saga/index.d.ts b/types/next-redux-saga/index.d.ts index b7575fba16..0366868d97 100644 --- a/types/next-redux-saga/index.d.ts +++ b/types/next-redux-saga/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/bmealhouse/next-redux-saga // Definitions by: Leo Cavalcante // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { ComponentType } from "react"; diff --git a/types/next-redux-wrapper/index.d.ts b/types/next-redux-wrapper/index.d.ts index 16af858743..cbf56579d5 100644 --- a/types/next-redux-wrapper/index.d.ts +++ b/types/next-redux-wrapper/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Steve // Jungwoo-An // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 /// diff --git a/types/react-intl-redux/index.d.ts b/types/react-intl-redux/index.d.ts index 9d9e805df9..4410e7c019 100644 --- a/types/react-intl-redux/index.d.ts +++ b/types/react-intl-redux/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/ratson/react-intl-redux // Definitions by: Karol Janyst // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { Action, AnyAction } from "redux" import { Provider as ReduxProvider } from "react-redux" diff --git a/types/react-lifecycle-component/index.d.ts b/types/react-lifecycle-component/index.d.ts index 315d04f7fb..bb6dc65dd8 100644 --- a/types/react-lifecycle-component/index.d.ts +++ b/types/react-lifecycle-component/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/JamieDixon/react-lifecycle-component // Definitions by: Alexander Fisher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { ComponentLifecycle, Component, ComponentClass } from 'react'; import { Connect } from 'react-redux'; diff --git a/types/react-redux-toastr/index.d.ts b/types/react-redux-toastr/index.d.ts index fc11da9c43..9a7a115725 100644 --- a/types/react-redux-toastr/index.d.ts +++ b/types/react-redux-toastr/index.d.ts @@ -4,7 +4,7 @@ // Artyom Stukans // Mika Kuitunen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { Component } from 'react'; import { Action, Reducer } from 'redux'; diff --git a/types/react-router-redux/index.d.ts b/types/react-router-redux/index.d.ts index 9dfbd58c11..7abdc88505 100644 --- a/types/react-router-redux/index.d.ts +++ b/types/react-router-redux/index.d.ts @@ -4,7 +4,7 @@ // Shoya Tanaka // Mykolas // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { Store, diff --git a/types/redux-auth-wrapper/index.d.ts b/types/redux-auth-wrapper/index.d.ts index 728be4a54b..3ec88b50dc 100644 --- a/types/redux-auth-wrapper/index.d.ts +++ b/types/redux-auth-wrapper/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/mjrussell/redux-auth-wrapper // Definitions by: Karol Janyst // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { ComponentClass, StatelessComponent, ComponentType, ReactType } from "react"; diff --git a/types/redux-devtools/index.d.ts b/types/redux-devtools/index.d.ts index 234fb9a4bb..ddead025ff 100644 --- a/types/redux-devtools/index.d.ts +++ b/types/redux-devtools/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/gaearon/redux-devtools // Definitions by: Petryshyn Sergii // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import * as React from 'react'; import { GenericStoreEnhancer } from 'redux'; diff --git a/types/redux-form/index.d.ts b/types/redux-form/index.d.ts index e80c196c0a..5851728369 100644 --- a/types/redux-form/index.d.ts +++ b/types/redux-form/index.d.ts @@ -12,7 +12,7 @@ // Maddi Joyce // Kamil Wojcik // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.9 +// TypeScript Version: 3.0 import { ComponentClass, StatelessComponent, diff --git a/types/redux-form/v6/index.d.ts b/types/redux-form/v6/index.d.ts index a8209a7643..5127457884 100644 --- a/types/redux-form/v6/index.d.ts +++ b/types/redux-form/v6/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/erikras/redux-form // Definitions by: Carson Full , Daniel Lytkin , Karol Janyst , Luka Zakrajsek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import { ComponentClass, From 2d5a8af9f819fad592387f8b4ce3731643125b05 Mon Sep 17 00:00:00 2001 From: Boris Sergeyev Date: Thu, 22 Nov 2018 22:18:01 +0100 Subject: [PATCH 061/792] [react-redux] used whitespace consistently (no tabs) --- types/react-redux/index.d.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index 1cccae6d01..bf65d89fd5 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -65,11 +65,11 @@ export type AdvancedComponentDecorator = * DecorationTargetProps[P] definition, its definition will be that of InjectedProps[P] */ export type Matching = { - [P in keyof DecorationTargetProps]: P extends keyof InjectedProps - ? InjectedProps[P] extends DecorationTargetProps[P] - ? DecorationTargetProps[P] - : InjectedProps[P] - : DecorationTargetProps[P]; + [P in keyof DecorationTargetProps]: P extends keyof InjectedProps + ? InjectedProps[P] extends DecorationTargetProps[P] + ? DecorationTargetProps[P] + : InjectedProps[P] + : DecorationTargetProps[P]; }; /** @@ -95,16 +95,16 @@ export type GetProps = C extends ComponentType ? P : never; // Applies LibraryManagedAttributes (proper handling of defaultProps // and propTypes), as well as defines WrappedComponent. export type ConnectedComponentClass = ComponentClass> & { - WrappedComponent: C; + WrappedComponent: C; }; // Injects props and removes them from the prop requirements. // Will not pass through the injected props if they are passed in during // render. Also adds new prop requirements from TNeedsProps. export type InferableComponentEnhancerWithProps = - >>>( - component: C - ) => ConnectedComponentClass, keyof Shared>> & TNeedsProps>; + >>>( + component: C + ) => ConnectedComponentClass, keyof Shared>> & TNeedsProps>; // Injects props and removes them from the prop requirements. // Will not pass through the injected props if they are passed in during From 3667c06d4542fdc415e5b43accf66c5a44cde4d6 Mon Sep 17 00:00:00 2001 From: Markus Lasermann Date: Fri, 23 Nov 2018 10:05:15 +0100 Subject: [PATCH 062/792] travis build could not parse version --- types/react-splitter-layout/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-splitter-layout/index.d.ts b/types/react-splitter-layout/index.d.ts index ec25b5fe1a..4ee438e983 100644 --- a/types/react-splitter-layout/index.d.ts +++ b/types/react-splitter-layout/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/zesik/react-splitter-layout#readme // Definitions by: Markus Lasermann // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.1.6 +// TypeScript Version: 2.8 import * as React from "react"; From 63e3bac336f8fcccf25224f77202a6a88f5e041c Mon Sep 17 00:00:00 2001 From: Markus Lasermann Date: Fri, 23 Nov 2018 10:33:36 +0100 Subject: [PATCH 063/792] tslint --- types/react-splitter-layout/index.d.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/types/react-splitter-layout/index.d.ts b/types/react-splitter-layout/index.d.ts index 4ee438e983..29273e87ef 100644 --- a/types/react-splitter-layout/index.d.ts +++ b/types/react-splitter-layout/index.d.ts @@ -1,17 +1,15 @@ -// Type definitions for react-splitter-layout v3.0.1 -// Project: https://github.com/zesik/react-splitter-layout#readme -// Definitions by: Markus Lasermann +// Type definitions for react-splitter-layout 3.0 +// Project: https://github.com/zesik/react-splitter-layout +// Definitions by: Markus Lasermann // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as React from "react"; -export default SplitterLayout; - -declare class SplitterLayout extends React.PureComponent { +export default class SplitterLayout extends React.PureComponent { } -type TPrimaryIndex = 0|1; +export type TPrimaryIndex = 0|1; export interface SplitterLayoutProps { /** @@ -97,4 +95,3 @@ export interface SplitterLayoutProps { */ onSecondaryPaneSizeChange?: (value: number) => void; } - From e547598a4f1c96bf1bff1774d0fc173b977ecb8d Mon Sep 17 00:00:00 2001 From: Markus Lasermann Date: Fri, 23 Nov 2018 11:34:42 +0100 Subject: [PATCH 064/792] fix tests --- types/react-splitter-layout/react-splitter-layout-tests.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react-splitter-layout/react-splitter-layout-tests.tsx b/types/react-splitter-layout/react-splitter-layout-tests.tsx index 1f97db7077..fa9860a2b7 100644 --- a/types/react-splitter-layout/react-splitter-layout-tests.tsx +++ b/types/react-splitter-layout/react-splitter-layout-tests.tsx @@ -1,11 +1,11 @@ import * as React from "react"; -import SplitterLayout, {SplitterLayoutProps} from "react-splitter-layout"; +import SplitterLayout, { SplitterLayoutProps } from "react-splitter-layout"; -export class SplitterLayoutTest extends React.PureComponent<{}> { +export class SplitterLayoutTest extends React.PureComponent { render(): JSX.Element { const props: SplitterLayoutProps = { percentage: true, - secondaryInitialSize: 30, + secondaryInitialSize: 40, }; return ( From f03ea514f73de0a92337a3ccfabf18559ff6a432 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 21 Nov 2018 16:49:40 +0100 Subject: [PATCH 065/792] Update types for ltx --- types/ltx/index.d.ts | 26 +++--- types/ltx/lib/Element.d.ts | 97 ++++++++++---------- types/ltx/lib/Parser.d.ts | 14 ++- types/ltx/lib/clone.d.ts | 4 +- types/ltx/lib/createElement.d.ts | 8 +- types/ltx/lib/equal.d.ts | 10 ++- types/ltx/lib/escape.d.ts | 8 +- types/ltx/lib/is.d.ts | 8 +- types/ltx/lib/parse.d.ts | 5 +- types/ltx/lib/stringify.d.ts | 4 +- types/ltx/lib/tag.d.ts | 4 +- types/ltx/lib/tagString.d.ts | 2 +- types/ltx/ltx-tests.ts | 148 ++++++++++++++++++++++++++++--- types/ltx/tslint.json | 8 +- 14 files changed, 250 insertions(+), 96 deletions(-) diff --git a/types/ltx/index.d.ts b/types/ltx/index.d.ts index 33311a3175..1c313c5541 100644 --- a/types/ltx/index.d.ts +++ b/types/ltx/index.d.ts @@ -1,17 +1,17 @@ -// Type definitions for ltx 2.6 +// Type definitions for ltx 2.8 // Project: github.com/node-xmpp/ltx/ // Definitions by: PJakcson +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 -export {Element } from './lib/Element'; -export {nameEqual, attrsEqual, childrenEqual, equal} from './lib/equal'; -export {isNode, isElement, isText} from './lib/is'; -export {clone} from './lib/clone'; -export {createElement} from './lib/createElement'; -export {escapeXML, unescapeXML, escapeXMLText, unescapeXMLText} from './lib/escape'; -export {Parser} from './lib/Parser'; -export {parse} from './lib/parse'; -export {tag} from './lib/tag'; -export {tagString} from './lib/tagString'; -export {stringify} from './lib/stringify'; +export * from './lib/Element'; +export * from './lib/equal'; +export * from './lib/is'; +export * from './lib/clone'; +export * from './lib/createElement'; +export * from './lib/escape'; +export * from './lib/Parser'; +export * from './lib/parse'; +export * from './lib/tag'; +export * from './lib/tagString'; +export * from './lib/stringify'; diff --git a/types/ltx/lib/Element.d.ts b/types/ltx/lib/Element.d.ts index 203eaa93b6..7f0d3de62e 100644 --- a/types/ltx/lib/Element.d.ts +++ b/types/ltx/lib/Element.d.ts @@ -1,21 +1,26 @@ +import { clone } from './clone'; + +export type Node = Element | TextNode; +export type TextNode = string | number; + /** * Element * * Attributes are in the element.attrs object. Children is a list of * either other Elements or Strings for text content. - **/ -export declare class Element { + */ +export class Element { name: string; - parent: Element; + parent: Element | null; children: Element[]; - attrs: any; + attrs: { [attrName: string]: any }; - constructor(name: string, attrs?: any); + constructor(name: string, attrs?: string | { [attrName: string]: any }); /** * if (element.is('message', 'jabber:client')) ... - **/ - is(name: string, xmlns?: any): boolean; + */ + is(name: string, xmlns?: string): boolean; /** * without prefix. @@ -24,50 +29,44 @@ export declare class Element { /** * retrieves the namespace of the current element, upwards recursively - **/ - getNS(): any; + */ + getNS(): string | undefined; /** * find the namespace to the given prefix, upwards recursively - **/ - findNS(prefix: string): any; + */ + findNS(prefix: string): string | undefined; /** * Recursiverly gets all xmlns defined, in the form of {url:prefix} - **/ - getXmlns(): any; + */ + getXmlns(): { [key: string]: string }; - setAttrs(attrs: any): void; + setAttrs(attrs: string | { [attrName: string]: any }): void; /** - * xmlns can be null, returns the matching attribute. - **/ - getAttr(name: string, xmlns?: any): any; + * returns the matching attribute. + */ + getAttr(name: string, xmlns?: string): any; - /** - * xmlns can be null - **/ - getChild(name: string, xmlns?: any): Element; + getChild(name: string, xmlns?: string): Element | undefined; - /** - * xmlns can be null - **/ - getChildren(name: string, xmlns?: any): Element[]; + getChildren(name: string, xmlns?: string): Element[]; - /** - * xmlns and recursive can be null - **/ - getChildByAttr(attr: any, val: any, xmlns?: any, recursive?: any): Element; + getChildByAttr( + attr: string, + val: any, + xmlns?: string, + recursive?: boolean + ): Element | undefined; + getChildrenByAttr(attr: string, val: any, xmlns?: string, recursive?: boolean): Element[]; - /** - * xmlns and recursive can be null - **/ - getChildrenByAttr(attr: any, val: any, xmlns?: any, recursive?: any): Element[]; + getChildrenByFilter(filter: (child: Node) => boolean, recursive?: boolean): Element[]; getText(): string; - getChildText(name: string, xmlns?: any): string; + getChildText(name: string, xmlns?: string): string | null; /** * Return all direct descendents that are Elements. @@ -77,37 +76,39 @@ export declare class Element { getChildElements(): Element[]; /** returns uppermost parent */ - root(): Element; + root(): Element | this; - tree(): Element; + tree(): Element | this; /** just parent or itself */ - up(): Element; + up(): Element | this; /** create child node and return it */ - c(name: string, attrs?: any): Element; + c(name: string, attrs?: { [key: string]: any }): Element; + + cnode(child: T): T; /** add text node and return element */ - t(text: string): Element; + t(text: TextNode): this; /** * Either: * el.remove(childEl) * el.remove('author', 'urn:...') */ - remove(el: Element, xmlns?: any): Element; + remove(el: Element | string, xmlns?: string): this; - clone(): Element; + clone: typeof clone; - text(val: string): string; + text(val?: string): string; - attr(attr: any, val: any): any; + attr(attr: string, val?: any): any; toString(): string; - toJSON(): any; + toJSON(): ElementJson; - write(writer: any): void; + write(writer: (part: string) => void): void; nameEquals(el: Element): boolean; @@ -117,3 +118,9 @@ export declare class Element { equals(el: Element): boolean; } + +export interface ElementJson { + name: string; + attrs: { [attrName: string]: any }; + children: Array; +} diff --git a/types/ltx/lib/Parser.d.ts b/types/ltx/lib/Parser.d.ts index 083e3ace66..463029286f 100644 --- a/types/ltx/lib/Parser.d.ts +++ b/types/ltx/lib/Parser.d.ts @@ -1,5 +1,15 @@ /// import { EventEmitter } from 'events'; -export declare class Parser extends EventEmitter { - constructor(options?: any); +import { Element } from './Element'; + +export class Parser extends EventEmitter { + constructor(options?: ParserOptions); + + write(data: string): void; + end(data: string): void; +} + +export interface ParserOptions { + Parser?: typeof Parser; + Element?: typeof Element; } diff --git a/types/ltx/lib/clone.d.ts b/types/ltx/lib/clone.d.ts index 41193a3f40..15369e00d5 100644 --- a/types/ltx/lib/clone.d.ts +++ b/types/ltx/lib/clone.d.ts @@ -1 +1,3 @@ -export declare function clone(el: any): any; +import { Element } from './Element'; + +export function clone(el: T): T; diff --git a/types/ltx/lib/createElement.d.ts b/types/ltx/lib/createElement.d.ts index c372f11150..21527ae1b6 100644 --- a/types/ltx/lib/createElement.d.ts +++ b/types/ltx/lib/createElement.d.ts @@ -1,2 +1,6 @@ -import { Element } from './Element'; -export declare function createElement(name: string, attrs: any): Element; +import { Element, Node } from './Element'; +export function createElement( + name: string, + attrs?: string | { [attrName: string]: any }, + ...children: Node[] +): Element; diff --git a/types/ltx/lib/equal.d.ts b/types/ltx/lib/equal.d.ts index 520555e098..f7548c526b 100644 --- a/types/ltx/lib/equal.d.ts +++ b/types/ltx/lib/equal.d.ts @@ -1,4 +1,6 @@ -export declare function nameEqual(a: any, b: any): boolean; -export declare function attrsEqual(a: any, b: any): boolean; -export declare function childrenEqual(a: any, b: any): boolean; -export declare function equal(a: any, b: any): boolean; +import { Element } from './Element'; + +export function nameEqual(a: Element, b: Element): boolean; +export function attrsEqual(a: Element, b: Element): boolean; +export function childrenEqual(a: Element, b: Element): boolean; +export function equal(a: Element, b: Element): boolean; diff --git a/types/ltx/lib/escape.d.ts b/types/ltx/lib/escape.d.ts index 4bc45c223a..d390e860ed 100644 --- a/types/ltx/lib/escape.d.ts +++ b/types/ltx/lib/escape.d.ts @@ -1,4 +1,4 @@ -export declare function escapeXML(s: string): string; -export declare function unescapeXML(s: string): string; -export declare function escapeXMLText(s: string): string; -export declare function unescapeXMLText(s: string): string; +export function escapeXML(s: string): string; +export function unescapeXML(s: string): string; +export function escapeXMLText(s: string): string; +export function unescapeXMLText(s: string): string; diff --git a/types/ltx/lib/is.d.ts b/types/ltx/lib/is.d.ts index 6515d23f80..e62d919267 100644 --- a/types/ltx/lib/is.d.ts +++ b/types/ltx/lib/is.d.ts @@ -1,3 +1,5 @@ -export declare function isNode(el: any): boolean; -export declare function isElement(el: any): boolean; -export declare function isText(el: any): boolean; +import { Element, Node } from './Element'; + +export function isNode(el: any): el is Node; +export function isElement(el: any): el is Element; +export function isText(el: any): el is string; diff --git a/types/ltx/lib/parse.d.ts b/types/ltx/lib/parse.d.ts index cc4073113a..0e0a9b17cb 100644 --- a/types/ltx/lib/parse.d.ts +++ b/types/ltx/lib/parse.d.ts @@ -1 +1,4 @@ -export declare function parse(data: any, options?: any): any; +import { ParserOptions, Parser } from './Parser'; +import { Element } from './Element'; + +export function parse(data: string, options?: ParserOptions | Parser): Element; diff --git a/types/ltx/lib/stringify.d.ts b/types/ltx/lib/stringify.d.ts index 770f7d324f..9913f2318c 100644 --- a/types/ltx/lib/stringify.d.ts +++ b/types/ltx/lib/stringify.d.ts @@ -1 +1,3 @@ -export declare function stringify(el: any, indent: any, level: any): string; +import { Element } from './Element'; + +export function stringify(el: Element, indent?: number, level?: number): string; diff --git a/types/ltx/lib/tag.d.ts b/types/ltx/lib/tag.d.ts index 8bbcb6fe7b..11a9784bf0 100644 --- a/types/ltx/lib/tag.d.ts +++ b/types/ltx/lib/tag.d.ts @@ -1 +1,3 @@ -export declare function tag(d: any): any; +import { Element } from './Element'; + +export function tag(literals: string[], ...substitutions: string[]): Element; diff --git a/types/ltx/lib/tagString.d.ts b/types/ltx/lib/tagString.d.ts index 44036ce037..619ccbdb23 100644 --- a/types/ltx/lib/tagString.d.ts +++ b/types/ltx/lib/tagString.d.ts @@ -1 +1 @@ -export declare function tagString(d: any): string; +export function tagString(literals: string[], ...substitutions: string[]): string; diff --git a/types/ltx/ltx-tests.ts b/types/ltx/ltx-tests.ts index 522b7673c8..a7342ef54b 100644 --- a/types/ltx/ltx-tests.ts +++ b/types/ltx/ltx-tests.ts @@ -1,21 +1,147 @@ import * as ltx from 'ltx'; -ltx.parse(''); +let el: ltx.Element = null as any; +let maybeEl: ltx.Element | undefined = null as any; +let els: ltx.Element[] = []; +let bool: boolean; +const any: any = null; +let str: string = null as any; -const getChildTextElement = ltx.parse('body text') as ltx.Element; -if (getChildTextElement.getChildText('child') !== 'body text') { - throw new Error("body does not match"); +el = ltx.clone(el); + +bool = ltx.nameEqual(el, el); +bool = ltx.attrsEqual(el, el); +bool = ltx.childrenEqual(el, el); +bool = ltx.equal(el, el); + +el = ltx.createElement('el'); +el = ltx.createElement('el', 'xml'); +el = ltx.createElement('el', { foo: 'bar' }); +el = ltx.createElement('el', { foo: 'bar' }, el); +el = ltx.createElement('el', { foo: 'bar' }, 'hi'); + +if (ltx.isNode(any)) { + // $ExpectType Node + any; +} +if (ltx.isElement(any)) { + // $ExpectType Element + any; +} +if (ltx.isText(any)) { + // $ExpectType string + any; } -const p = new ltx.Parser(); +str = ltx.escapeXML(str); +str = ltx.unescapeXML(str); +str = ltx.escapeXMLText(str); +str = ltx.unescapeXMLText(str); + +el = ltx.parse(''); +el = ltx.parse('', (null as any) as ltx.Parser); +el = ltx.parse('', { Parser: (null as any) as typeof ltx.Parser }); +el = ltx.parse('', { Element: (null as any) as typeof ltx.Element }); + +el = ltx.tag(['document'], 'foo'); +str = ltx.tagString(['document'], 'foo'); + +str = ltx.stringify(el); +str = ltx.stringify(el, 1); +str = ltx.stringify(el, 1, 1); + +const getChildTextElement = ltx.parse('body text'); +if (getChildTextElement.getChildText('child') !== 'body text') { + throw new Error('body does not match'); +} + +let p: ltx.Parser; +p = new ltx.Parser(); +p = new ltx.Parser({ Parser: (null as any) as typeof ltx.Parser }); +p = new ltx.Parser({ Element: (null as any) as typeof ltx.Element }); p.on('tree', (ignored: any) => {}); - p.on('error', (ignored: any) => {}); -const el = new ltx.Element('root').c('children'); -el.c('child', {age: 5}).t('Hello').up() - .c('child', {age: 7}).t('Hello').up() - .c('child', {age: 99}).t('Hello').up(); +el = new ltx.Element('root').c('children'); -el.root().toString(); +bool = el.is('el'); +bool = el.is('el', 'ns'); +str = el.getName(); +let s: string | undefined = el.getNS(); +s = el.findNS('ns'); +const xmlns: { [key: string]: string } = el.getXmlns(); +el.setAttrs('ho'); +el.setAttrs({ my: 'attr' }); +el.getAttr('ho'); +el.getAttr('ho', 'ns'); +maybeEl = el.getChild('el'); +maybeEl = el.getChild('el', 'ns'); +els = el.getChildren('el'); +els = el.getChildren('el', 'ns'); +maybeEl = el.getChildByAttr('my', 'attr'); +maybeEl = el.getChildByAttr('my', 'attr', 'ns'); +maybeEl = el.getChildByAttr('my', 'attr', 'ns', true); +els = el.getChildrenByAttr('my', 'attr'); +els = el.getChildrenByAttr('my', 'attr', 'ns'); +els = el.getChildrenByAttr('my', 'attr', 'ns', true); +els = el.getChildrenByFilter(child => { + // $ExpectType Node + child; + return true; +}); +els = el.getChildrenByFilter(child => { + // $ExpectType Node + child; + return true; +}, true); +str = el.getText(); +let maybeS: string | null = el.getChildText('hi'); +maybeS = el.getChildText('hi', 'ns'); +els = el.getChildElements(); + +class MyEl extends ltx.Element { + foo: 'bar'; +} +let myEl = new MyEl('el'); + +// $ExpectType Element | MyEl +myEl.root(); +// $ExpectType Element | MyEl +myEl.tree(); +// $ExpectType Element | MyEl +myEl.up(); + +el = el.c('hi'); +el = el.c('hi', { my: 'attr' }); +myEl = myEl.cnode(myEl); +myEl = myEl.t('hi'); +myEl = myEl.t(1); +myEl = myEl.remove(el); +myEl = myEl.remove('el'); +myEl = myEl.remove('el', 'ns'); +myEl = myEl.clone(myEl); +str = el.text(); +str = el.text('val'); +el.attr('my'); +el.attr('my', 'attr'); +str = el.toString(); +const json: ltx.ElementJson = el.toJSON(); +el.write(part => { + // $ExpectType string + part; +}); +bool = el.nameEquals(el); +bool = el.attrsEquals(el); +bool = el.childrenEquals(el); +bool = el.equals(el); + +el.c('child', { age: 5 }) + .t('Hello') + .up() + .c('child', { age: 7 }) + .t('Hello') + .up() + .c('child', { age: 99 }) + .t('Hello') + .up(); diff --git a/types/ltx/tslint.json b/types/ltx/tslint.json index 5bb1e8735d..f93cf8562a 100644 --- a/types/ltx/tslint.json +++ b/types/ltx/tslint.json @@ -1,9 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - // All are TODOs - "jsdoc-format": false, - "no-consecutive-blank-lines": false, - "strict-export-declare-modifiers": false - } + "extends": "dtslint/dt.json" } From 16033f3b89831cdd6f23c1236ed8a0b741ca522e Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 19 Nov 2018 21:43:50 +0100 Subject: [PATCH 066/792] Correct return types for p-defer --- types/p-defer/index.d.ts | 17 +++++++++-------- types/p-defer/p-defer-tests.ts | 12 ++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/types/p-defer/index.d.ts b/types/p-defer/index.d.ts index 7eff607e7d..8386706d89 100644 --- a/types/p-defer/index.d.ts +++ b/types/p-defer/index.d.ts @@ -1,16 +1,17 @@ // Type definitions for p-defer 1.0 // Project: https://github.com/sindresorhus/p-defer // Definitions by: Sam Verschueren +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare namespace pDefer { - interface DeferredPromise { - resolve(value?: U | PromiseLike): Promise; - reject(reason: any): Promise; - promise: Promise; - } -} +export = pDefer; declare function pDefer(): pDefer.DeferredPromise; -export = pDefer; +declare namespace pDefer { + interface DeferredPromise { + resolve(value?: T | PromiseLike): void; + reject(reason: any): void; + promise: Promise; + } +} diff --git a/types/p-defer/p-defer-tests.ts b/types/p-defer/p-defer-tests.ts index 9ea4647620..f61bce624b 100644 --- a/types/p-defer/p-defer-tests.ts +++ b/types/p-defer/p-defer-tests.ts @@ -1,13 +1,13 @@ import pDefer = require('p-defer'); -function delay(deferred: pDefer.DeferredPromise, ms: number) { +function delay(deferred: pDefer.DeferredPromise, ms: number) { setTimeout(deferred.resolve, ms, 'πŸ¦„'); return deferred.promise; } -let s: string; -async function f() { s = await delay(pDefer(), 100); } +const s: Promise = delay(pDefer(), 100); -async function u() { - const u: Promise = pDefer().resolve(); -} +// $ExpectType void +pDefer().resolve(); +// $ExpectType void +pDefer().reject('oh no'); From 64df3bfb11d384c4d404c71e05ff47aea9b7e8cb Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Fri, 23 Nov 2018 17:53:22 +0100 Subject: [PATCH 067/792] Add mcrypt@0.1 --- types/mcrypt/index.d.ts | 31 ++++++++++++++++++++++ types/mcrypt/mcrypt-tests.ts | 51 ++++++++++++++++++++++++++++++++++++ types/mcrypt/tsconfig.json | 16 +++++++++++ types/mcrypt/tslint.json | 1 + 4 files changed, 99 insertions(+) create mode 100644 types/mcrypt/index.d.ts create mode 100644 types/mcrypt/mcrypt-tests.ts create mode 100644 types/mcrypt/tsconfig.json create mode 100644 types/mcrypt/tslint.json diff --git a/types/mcrypt/index.d.ts b/types/mcrypt/index.d.ts new file mode 100644 index 0000000000..945cb88e59 --- /dev/null +++ b/types/mcrypt/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for mcrypt 0.1 +// Project: https://github.com/tugrul/node-mcrypt +// Definitions by: Alan Plum +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +export function getAlgorithmNames(): string[]; +export function getModeNames(): string[]; + +export class MCrypt { + constructor(algorithm: string, mode: string); + open(key: string | Buffer, iv?: string | Buffer): void; + encrypt(plaintext: string | Buffer): Buffer; + decrypt(ciphertext: Buffer): Buffer; + generateIv(): Buffer; + validateKeySize(validate: boolean): void; + validateIvSize(validate: boolean): void; + selfTest(): boolean; + isBlockAlgorithmMode(): boolean; + isBlockAlgorithm(): boolean; + isBlockMode(): boolean; + getBlockSize(): number; + getKeySize(): number; + getSupportedKeySizes(): number[]; + getIvSize(): number; + hasIv(): boolean; + getAlgorithmName(): string; + getModeName(): string; +} diff --git a/types/mcrypt/mcrypt-tests.ts b/types/mcrypt/mcrypt-tests.ts new file mode 100644 index 0000000000..66614e08e3 --- /dev/null +++ b/types/mcrypt/mcrypt-tests.ts @@ -0,0 +1,51 @@ +import { getAlgorithmNames, getModeNames, MCrypt } from "mcrypt"; + +let plaintext: Buffer; +let ciphertext: Buffer; + +for (const algo of getAlgorithmNames()) { + console.log(algo.toUpperCase()); +} +for (const mode of getModeNames()) { + console.log(mode.toUpperCase()); +} + +const desEcb = new MCrypt("des", "ecb"); +desEcb.open("madepass"); + +ciphertext = desEcb.encrypt("too many secrets"); +console.log(ciphertext.toString("base64")); + +plaintext = desEcb.decrypt(ciphertext); +console.log(plaintext.toString()); + +const blowfishCfb = new MCrypt("blowfish", "cfb"); +const iv = blowfishCfb.generateIv(); +blowfishCfb.open("somekey", iv); +ciphertext = blowfishCfb.encrypt("sometext"); +console.log(Buffer.concat([iv, ciphertext]).toString("base64")); + +const bfEcb = new MCrypt("blowfish", "ecb"); +bfEcb.validateKeySize(false); +bfEcb.open("typeconfig.sys^_-"); + +const rjCbc = new MCrypt("rijndael-256", "cbc"); +rjCbc.validateIvSize(false); +rjCbc.open("$verysec$retkey$", "foobar"); + +console.log(blowfishCfb.getBlockSize() * 8); +console.log(blowfishCfb.getKeySize() * 8); +console.log(blowfishCfb.getSupportedKeySizes().map(v => v * 8)); +console.log(blowfishCfb.getIvSize() * 8); +console.log(blowfishCfb.getAlgorithmName().toUpperCase()); +console.log(blowfishCfb.getModeName().toUpperCase()); + +function assertBool(value: boolean) { + return value; +} + +assertBool(blowfishCfb.selfTest()); +assertBool(blowfishCfb.isBlockAlgorithmMode()); +assertBool(blowfishCfb.isBlockAlgorithm()); +assertBool(blowfishCfb.isBlockMode()); +assertBool(blowfishCfb.hasIv()); diff --git a/types/mcrypt/tsconfig.json b/types/mcrypt/tsconfig.json new file mode 100644 index 0000000000..1bb1454ce5 --- /dev/null +++ b/types/mcrypt/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "mcrypt-tests.ts"] +} diff --git a/types/mcrypt/tslint.json b/types/mcrypt/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mcrypt/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 3df7d2836e432e949b26de57741265aad9cf1e8d Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Fri, 23 Nov 2018 23:45:29 +0100 Subject: [PATCH 068/792] Add promised-ldap@0.3 --- types/promised-ldap/index.d.ts | 95 ++++++++++++++++++++++ types/promised-ldap/promised-ldap-tests.ts | 39 +++++++++ types/promised-ldap/tsconfig.json | 16 ++++ types/promised-ldap/tslint.json | 1 + 4 files changed, 151 insertions(+) create mode 100644 types/promised-ldap/index.d.ts create mode 100644 types/promised-ldap/promised-ldap-tests.ts create mode 100644 types/promised-ldap/tsconfig.json create mode 100644 types/promised-ldap/tslint.json diff --git a/types/promised-ldap/index.d.ts b/types/promised-ldap/index.d.ts new file mode 100644 index 0000000000..53f215b2b8 --- /dev/null +++ b/types/promised-ldap/index.d.ts @@ -0,0 +1,95 @@ +// Type definitions for promised-ldap 0.3 +// Project: https://github.com/stewartml/promised-ldap#readme +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { EventEmitter } from "events"; +import * as ldap from "ldapjs"; + +declare class Client extends EventEmitter { + constructor({ url }: { url: string }); + + search( + base: string, + options: ldap.SearchOptions, + controls?: ldap.Control | ldap.Control[] + ): Promise<{ + entries: any[]; + references: any[]; + }>; + + authenticate(base: string, dn: string, password: string): Promise; + authenticateUser( + base: string, + dn: string, + password: string + ): Promise<{ name: string; email: string; groups: string[] } | null>; + + bind( + dn: string, + password: string, + controls?: ldap.Control | ldap.Control[] + ): Promise; + + add( + name: string, + entry: object, + controls?: ldap.Control | ldap.Control[] + ): Promise; + + compare( + name: string, + attr: string, + value: string, + controls?: ldap.Control | ldap.Control[] + ): Promise; + + del(name: string, controls?: ldap.Control | ldap.Control[]): Promise; + + exop( + name: string, + value: string, + controls?: ldap.Control | ldap.Control[] + ): Promise; + + modify( + name: string, + change: ldap.Change | ldap.Change[], + controls?: ldap.Control | ldap.Control[] + ): Promise; + + modifyDN( + name: string, + newName: string, + controls?: ldap.Control | ldap.Control[] + ): Promise; + + _search( + base: string, + options: ldap.SearchOptions, + controls?: ldap.Control | ldap.Control[], + _bypass?: boolean + ): Promise; + _search( + base: string, + options: ldap.SearchOptions, + _bypass: boolean + ): Promise; + + starttls( + options: object, + controls: ldap.Control | ldap.Control[], + _bypass?: boolean + ): Promise; + + unbind(): Promise; + + destroy(err?: any): void; +} + +declare namespace Client { + type SearchOptions = ldap.SearchOptions; +} + +export = Client; diff --git a/types/promised-ldap/promised-ldap-tests.ts b/types/promised-ldap/promised-ldap-tests.ts new file mode 100644 index 0000000000..b61f7ef6fc --- /dev/null +++ b/types/promised-ldap/promised-ldap-tests.ts @@ -0,0 +1,39 @@ +import ldap = require("promised-ldap"); +import ldapjs = require("ldapjs"); + +const client = new ldap({ + url: "ldap://127.0.0.1:1389" +}); + +client.authenticate("test", "cn=root", "secret").then((res: any) => { + console.log(res); +}); + +client.authenticateUser("test", "cn=root", "secret").then((res: any) => { + console.log(res); +}); + +client.bind("cn=root", "secret").catch((err: Error) => { + console.error(err); +}); + +const opts: ldap.SearchOptions = { + filter: "(&(l=Seattle)(email=*@foo.com))", + scope: "sub", + attributes: ["dn", "sn", "cn"] +}; + +client._search("o=example", opts).then((res: NodeJS.EventEmitter) => { + console.log(res); +}); + +const change = new ldapjs.Change({ + operation: "add", + modification: { + pets: ["cat", "dog"] + } +}); + +client.modify("cn=foo, o=example", change).catch((err: Error) => { + console.error(err); +}); diff --git a/types/promised-ldap/tsconfig.json b/types/promised-ldap/tsconfig.json new file mode 100644 index 0000000000..89b60715eb --- /dev/null +++ b/types/promised-ldap/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "promised-ldap-tests.ts"] +} diff --git a/types/promised-ldap/tslint.json b/types/promised-ldap/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/promised-ldap/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 1cef81059eccb564654a9942955300c2073bb3f3 Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Sat, 24 Nov 2018 01:45:43 +0100 Subject: [PATCH 069/792] Update index.d.ts --- types/promised-ldap/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/promised-ldap/index.d.ts b/types/promised-ldap/index.d.ts index 53f215b2b8..8b0182bea6 100644 --- a/types/promised-ldap/index.d.ts +++ b/types/promised-ldap/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for promised-ldap 0.3 -// Project: https://github.com/stewartml/promised-ldap#readme -// Definitions by: My Self +// Project: https://github.com/stewartml/promised-ldap +// Definitions by: Alan Plum // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 From c0df17945ec4488f75c6eb4cc121926601e901fc Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Sat, 24 Nov 2018 02:11:50 +0100 Subject: [PATCH 070/792] Added ldap-filters@2.2 --- types/ldap-filters/index.d.ts | 60 ++++++++++++++++++++++++ types/ldap-filters/ldap-filters-tests.ts | 28 +++++++++++ types/ldap-filters/tsconfig.json | 16 +++++++ types/ldap-filters/tslint.json | 1 + 4 files changed, 105 insertions(+) create mode 100644 types/ldap-filters/index.d.ts create mode 100644 types/ldap-filters/ldap-filters-tests.ts create mode 100644 types/ldap-filters/tsconfig.json create mode 100644 types/ldap-filters/tslint.json diff --git a/types/ldap-filters/index.d.ts b/types/ldap-filters/index.d.ts new file mode 100644 index 0000000000..46e1c24fa8 --- /dev/null +++ b/types/ldap-filters/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for ldap-filters 2.2 +// Project: https://github.com/tapmodo/node-ldap-filters +// Definitions by: Alan Plum +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +interface Filter { + toString(indent?: boolean | number): string; + simplify(): Filter; + match(data: object): boolean; +} + +declare namespace Filter { + let escape_chars: string[]; + let indent: number; + let indent_char: string; + let collapse_not: boolean; + + function escape(value: string): string; + function unescape(value: string): string; + function parse(input: string): Filter; + function matchString(data: string | string[], filter: Filter): boolean; + function matchSubstring(data: string | string[], filter: Filter): boolean; + function matchApprox(data: string | string[], filter: Filter): boolean; + function matchGTE(data: string | string[], filter: Filter): boolean; + function matchLTE(data: string | string[], filter: Filter): boolean; + function attribute(name: string): Attribute; + function AND(filters: Filter[]): Group; + function OR(filters: Filter[]): Group; + function NOT(filter: Filter): GroupNot; + + interface Group { + type: string; + comp: string; + filters: Filter[]; + toString(indent?: boolean | number): string; + match(data: object): boolean; + } + + interface GroupNot extends Group { + simplify(): Filter; + } + + interface Attribute { + name: string; + escapeChars: string[]; + escape(value: string): string; + present(): Filter; + raw(value: string): Filter; + equalTo(value: string): Filter; + endsWith(value: string): Filter; + startsWith(value: string): Filter; + contains(value: string): Filter; + approx(value: string): Filter; + lte(value: string): Filter; + gte(value: string): Filter; + } +} + +export = Filter; diff --git a/types/ldap-filters/ldap-filters-tests.ts b/types/ldap-filters/ldap-filters-tests.ts new file mode 100644 index 0000000000..5111af785e --- /dev/null +++ b/types/ldap-filters/ldap-filters-tests.ts @@ -0,0 +1,28 @@ +/// + +import Filter = require("ldap-filters"); + +Filter.collapse_not = false; + +const output = Filter.AND([ + Filter.attribute("givenName").equalTo("jenny"), + Filter.attribute("sn").equalTo("jensen") +]); + +console.log(output.toString()); + +Filter.parse("(&(givenName=jenny)(sn=jensen))"); + +Filter.parse("(&(uid=jenny))").simplify(); + +const filter = Filter.parse( + "(&(givenName=jenny)(sn=jensen)(|(c=us)(st=ontario)))" +); + +filter.toString(); +filter.toString(true); +filter.toString(2); + +const parsed = Filter.parse("(&(givenName~=jeni)(sn=jensen))"); +const data = { givenName: "Jenny", sn: "Jensen" }; +console.log(parsed.match(data)); diff --git a/types/ldap-filters/tsconfig.json b/types/ldap-filters/tsconfig.json new file mode 100644 index 0000000000..9d4f5aa560 --- /dev/null +++ b/types/ldap-filters/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "ldap-filters-tests.ts"] +} diff --git a/types/ldap-filters/tslint.json b/types/ldap-filters/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ldap-filters/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From da0630fa320071bbd5713ea86c11de6a50725b43 Mon Sep 17 00:00:00 2001 From: Hiroshi Ioka Date: Sat, 24 Nov 2018 13:51:49 +0900 Subject: [PATCH 071/792] @types/mockingoose: add new package --- types/mockingoose/index.d.ts | 40 ++++++++++++++++++++++++++ types/mockingoose/mockingoose-tests.ts | 9 ++++++ types/mockingoose/tsconfig.json | 23 +++++++++++++++ types/mockingoose/tslint.json | 1 + 4 files changed, 73 insertions(+) create mode 100644 types/mockingoose/index.d.ts create mode 100644 types/mockingoose/mockingoose-tests.ts create mode 100644 types/mockingoose/tsconfig.json create mode 100644 types/mockingoose/tslint.json diff --git a/types/mockingoose/index.d.ts b/types/mockingoose/index.d.ts new file mode 100644 index 0000000000..a1597bd4e5 --- /dev/null +++ b/types/mockingoose/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for mockingoose 2.11 +// Project: https://github.com/alonronin/mockingoose#readme +// Definitions by: Hiroshi Ioka +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +type Op = + | 'find' + | 'findOne' + | 'count' + | 'countDocuments' + | 'estimatedDocumentCount' + | 'distinct' + | 'findOneAndUpdate' + | 'findOneAndRemove' + | 'remove' + | 'update' + | 'deleteOne' + | 'deleteMany' + | 'save'; + +declare class Mock { + toReturn(expected: any, op?: Op): this; + reset(op: Op): this; + toJSON(): any; +} + +interface Target { + __mocks: any; + resetAll(): void; + toJSON(): any; +} + +type Proxy = Target & { + [index: string]: Mock; +}; + +declare const mockingoose: Proxy; + +export default mockingoose; diff --git a/types/mockingoose/mockingoose-tests.ts b/types/mockingoose/mockingoose-tests.ts new file mode 100644 index 0000000000..09a00ad274 --- /dev/null +++ b/types/mockingoose/mockingoose-tests.ts @@ -0,0 +1,9 @@ +import mockingoose from 'mockingoose'; + +mockingoose.User + .toReturn({ name: 'name' }) + .toReturn({ name: 'a name too' }, 'findOne') + .toReturn({ name: 'another name' }, 'save') + .reset('find'); + +mockingoose.resetAll(); diff --git a/types/mockingoose/tsconfig.json b/types/mockingoose/tsconfig.json new file mode 100644 index 0000000000..a6f171944a --- /dev/null +++ b/types/mockingoose/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mockingoose-tests.ts" + ] +} diff --git a/types/mockingoose/tslint.json b/types/mockingoose/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mockingoose/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From a169bc5dda5c595439062712c4d0429b4def512d Mon Sep 17 00:00:00 2001 From: TeamworkGuy2 Date: Sat, 24 Nov 2018 14:26:28 +0000 Subject: [PATCH 072/792] [cached-path-relative] Add documentation to new definition --- types/cached-path-relative/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/cached-path-relative/index.d.ts b/types/cached-path-relative/index.d.ts index 56076870bc..b2af5ea81c 100644 --- a/types/cached-path-relative/index.d.ts +++ b/types/cached-path-relative/index.d.ts @@ -3,6 +3,11 @@ // Definitions by: TeamworkGuy2 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/** + * Memoize the results of the path.relative function. path.relative can be an expensive operation + * if it happens a lot, and its results shouldn't change for the same arguments. + * Use it just like your normal path.relative, but it's memoized. + */ declare function cachedPathRelative(from: string, to: string): string; export = cachedPathRelative; From 16770fa6e199f01f83957339c25bc9ce1095329c Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Wed, 24 Oct 2018 08:11:51 -0400 Subject: [PATCH 073/792] [jquery] Add deprecation notice for `Event.which`. --- types/jquery/misc.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index 7b09b6a4dc..8488d49f00 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -4305,6 +4305,7 @@ $( "a" ).click(function( event ) { * For key or mouse events, this property indicates the specific key or button that was pressed. * @see \`{@link https://api.jquery.com/event.which/ }\` * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. * @example ​ ````Log which key was depressed. ```html From e64bea6d884096561c30e067804e9d58afde5926 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Fri, 26 Oct 2018 09:17:54 -0400 Subject: [PATCH 074/792] [jquery] Remove `jQuery.event.fixHooks`. See https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-event-props-and-jquery-event-fixhooks-removed. --- types/jquery/jquery-tests.ts | 16 ------- types/jquery/misc.d.ts | 74 -------------------------------- types/jquery/test/learn-tests.ts | 18 -------- 3 files changed, 108 deletions(-) diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 515715bf14..21b4f8fdef 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -8427,22 +8427,6 @@ function JQuery_Event() { } function JQuery_EventExtensions() { - function fixHooks() { - jQuery.event.fixHooks.drop = { - props: ['dataTransfer'], - filter(event, originalEvent) { - // $ExpectType Event - event; - // $ExpectType Event - originalEvent; - }, - }; - - // Weak type test. This may be removed if the TypeScript requirement is increased to 2.4+. - // $ExpectError - jQuery.event.fixHooks.drop = ['dataTransfer']; - } - function special() { jQuery.event.special.multiclick = { noBubble: true, diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index 8488d49f00..c466004c58 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -4734,11 +4734,6 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); * @see \`{@link https://learn.jquery.com/events/event-extensions/#jquery-event-props-array }\` */ props: string[]; - /** - * The `fixHooks` interface provides a per-event-type way to extend or normalize the event object that jQuery creates when it processes a _native_ browser event. - * @see \`{@link https://learn.jquery.com/events/event-extensions/#jquery-event-fixhooks-object }\` - */ - fixHooks: FixHooks; /** * The jQuery special event hooks are a set of per-event-name functions and properties that allow code to control the behavior of event processing within jQuery. The mechanism is similar to `fixHooks` in that the special event information is stored in `jQuery.event.special.NAME`, where `NAME` is the name of the special event. Event names are case sensitive. * @@ -4748,75 +4743,6 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); special: SpecialEventHooks; } - // region Fix hooks - // #region Fix hooks - - // Workaround for TypeScript 2.3 which does not have support for weak types handling. - type FixHook = { - /** - * Strings representing properties that should be copied from the browser's event object to the jQuery event object. If omitted, no additional properties are copied beyond the standard ones that jQuery copies and normalizes (e.g. `event.target` and `event.relatedTarget`). - */ - props: string[]; - } | { - /** - * jQuery calls this function after it constructs the `jQuery.Event` object, copies standard properties from `jQuery.event.props`, and copies the `fixHooks`-specific props (if any) specified above. The function can create new properties on the event object or modify existing ones. The second argument is the browser's native event object, which is also available in `event.originalEvent`. - * - * Note that for all events, the browser's native event object is available in `event.originalEvent`; if the jQuery event handler examines the properties there instead of jQuery's normalized `event` object, there is no need to create a `fixHooks` entry to copy or modify the properties. - * @example ​ ````For example, to set a hook for the "drop" event that copies the `dataTransfer` property, assign an object to `jQuery.event.fixHooks.drop`: -```javascript -jQuery.event.fixHooks.drop = { - props: [ "dataTransfer" ] -}; -``` - -Since fixHooks is an advanced feature and rarely used externally, jQuery does not include code or -interfaces to deal with conflict resolution. If there is a chance that some other code may be assigning -`fixHooks` to the same events, the code should check for an existing hook and take appropriate measures. -A simple solution might look like this: - -```javascript -if ( jQuery.event.fixHooks.drop ) { - throw new Error( "Someone else took the jQuery.event.fixHooks.drop hook!" ); -} - -jQuery.event.fixHooks.drop = { - props: [ "dataTransfer" ] -}; -``` - -When there are known cases of different plugins wanting to attach to the drop hook, this solution might be more appropriate: - -```javascript -var existingHook = jQuery.event.fixHooks.drop; - -if ( !existingHook ) { - jQuery.event.fixHooks.drop = { - props: [ "dataTransfer" ] - }; -} else { - if ( existingHook.props ) { - existingHook.props.push( "dataTransfer" ); - } else { - existingHook.props = [ "dataTransfer" ]; - } -} -``` - */ - filter(event: Event, originalEvent: _Event): void; - } | { - [key: string]: never; - }; - - /** - * The `fixHooks` interface provides a per-event-type way to extend or normalize the event object that jQuery creates when it processes a _native_ browser event. - * @see \`{@link https://learn.jquery.com/events/event-extensions/#jquery-event-fixhooks-object }\` - */ - interface FixHooks { - [event: string]: FixHook; - } - - // #endregion - // region Special event hooks // #region Special event hooks diff --git a/types/jquery/test/learn-tests.ts b/types/jquery/test/learn-tests.ts index 8ef5eb2cfa..523385b644 100644 --- a/types/jquery/test/learn-tests.ts +++ b/types/jquery/test/learn-tests.ts @@ -21,24 +21,6 @@ jQuery("a").greenify(); // Makes all the links green. // Events -function fixHooks() { - function setHook() { - jQuery.event.fixHooks.drop = { - props: ["dataTransfer"] - }; - } - - function conflictResolution() { - if (jQuery.event.fixHooks.drop) { - throw new Error("Someone else took the jQuery.event.fixHooks.drop hook!"); - } - - jQuery.event.fixHooks.drop = { - props: ["dataTransfer"] - }; - } -} - function special() { function defineSpecialEvent() { jQuery.event.special.pushy = { From 50b56a19ce4cb93b1de1f87ef029938068f0198c Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Fri, 26 Oct 2018 09:18:35 -0400 Subject: [PATCH 075/792] [jquery] Remove `jQuery.event.props`. See https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-event-props-and-jquery-event-fixhooks-removed. --- types/jquery/misc.d.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index c466004c58..5aa957f4c5 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -4727,13 +4727,6 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); // #region Event extensions interface EventExtensions { - /** - * jQuery defines an \`{@link https://api.jquery.com/category/events/event-object/ Event object}\` that represents a cross-browser subset of the information available when an event occurs. The `jQuery.event.props` property is an array of string names for properties that are always copied when jQuery processes a native browser event. (Events fired in code by `.trigger()` do not use this list, since the code can construct a `jQuery.Event` object with the needed values and trigger using that object.) - * - * To add a property name to this list, use `jQuery.event.props.push( "newPropertyName" )`. However, be aware that every event processed by jQuery will now attempt to copy this property name from the native browser event to jQuery's constructed event. If the property does not exist for that event type, it will get an undefined value. Adding many properties to this list can significantly reduce event delivery performance, so for infrequently-needed properties it is more efficient to use the value directly from `event.originalEvent` instead. If properties must be copied, you are strongly advised to use `jQuery.event.fixHooks` as of version 1.7. - * @see \`{@link https://learn.jquery.com/events/event-extensions/#jquery-event-props-array }\` - */ - props: string[]; /** * The jQuery special event hooks are a set of per-event-name functions and properties that allow code to control the behavior of event processing within jQuery. The mechanism is similar to `fixHooks` in that the special event information is stored in `jQuery.event.special.NAME`, where `NAME` is the name of the special event. Event names are case sensitive. * From 32e0482fb5df663b228e8eb7de1cde1c5b41f9b0 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 21 Oct 2018 09:54:12 -0400 Subject: [PATCH 076/792] [jquery] Remove `jQuery.Event(EventLike)` signatures and `EventLike` interface. These are undocumented and don't appear to be intended to be public. --- types/jquery/jquery-tests.ts | 10 ---------- types/jquery/misc.d.ts | 8 -------- 2 files changed, 18 deletions(-) diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 21b4f8fdef..eba206f323 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -8400,21 +8400,11 @@ function JQuery_Event() { function call_signature() { // $ExpectType Event & Coordinates $.Event('keydown', $('p').offset()); - - // $ExpectType Event & { type: string; } - $.Event({ - type: 'keydown' - }); } function constructor() { // $ExpectType Event & Coordinates new $.Event('keydown', $('p').offset()); - - // $ExpectType Event & { type: string; } - new $.Event({ - type: 'keydown' - }); } // https://stackoverflow.com/questions/49892574/trigger-a-jquery-3-event-with-ctrlkey-set diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index 5aa957f4c5..94f7279e63 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -3986,11 +3986,7 @@ $( "input" ).click(function() { // tslint:disable-next-line:no-unnecessary-generics (event: string, properties?: T): Event & T; // tslint:disable-next-line:no-unnecessary-generics - (properties: T): Event & T; - // tslint:disable-next-line:no-unnecessary-generics new (event: string, properties?: T): Event & T; - // tslint:disable-next-line:no-unnecessary-generics - new (properties: T): Event & T; } // Instance members @@ -4712,10 +4708,6 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); target: TTarget; } - interface EventLike { - type: string; - } - // #endregion interface EventHandler extends EventHandlerBase> { } From c1ec1c28e5c9f6e6f0cb16b37de27d7c66c5a513 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Fri, 26 Oct 2018 10:43:45 -0400 Subject: [PATCH 077/792] [jquery] Remove `JQuery.EventHandlerBase` from handler types. Handler types previously included `JQuery.EventHandlerBase`. This was a fix to what turned out to be a problem with `jQuery.proxy`. That issue was properly fixed by https://github.com/DefinitelyTyped/DefinitelyTyped/pull/29930. --- types/jquery/JQuery.d.ts | 136 +++---- types/jquery/jquery-tests.ts | 744 +---------------------------------- 2 files changed, 89 insertions(+), 791 deletions(-) diff --git a/types/jquery/JQuery.d.ts b/types/jquery/JQuery.d.ts index 7453457953..70cfaa0e03 100644 --- a/types/jquery/JQuery.d.ts +++ b/types/jquery/JQuery.d.ts @@ -1331,7 +1331,7 @@ $( "p" ).before( $( "b" ) ); */ bind(eventType: string, eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Attach a handler to an event for the elements. * @param eventType A string containing one or more DOM event types, such as "click" or "submit," or custom event names. @@ -1459,7 +1459,7 @@ $( "button" ).click(function() { ``` */ bind(eventType: string, - handler_preventBubble: JQuery.EventHandler | JQuery.EventHandlerBase> | false | null | undefined): this; + handler_preventBubble: JQuery.EventHandler | false | null | undefined): this; /** * Attach a handler to an event for the elements. * @param events An object containing one or more DOM event types and functions to execute for them. @@ -1485,7 +1485,7 @@ $( "div.test" ).bind({ }); ``` */ - bind(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>): this; + bind(events: JQuery.PlainObject | false>): this; /** * Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -1499,7 +1499,7 @@ $( "div.test" ).bind({ * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ blur(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1515,7 +1515,7 @@ $( "div.test" ).bind({ $( "p" ).blur(); ``` */ - blur(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + blur(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "change" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -1529,7 +1529,7 @@ $( "p" ).blur(); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ change(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "change" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1588,7 +1588,7 @@ $( "input[type='text']" ).change(function() { }); ``` */ - change(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + change(handler?: JQuery.EventHandler | false): this; /** * Get the children of each element in the set of matched elements, optionally filtered by a selector. * @param selector A string containing a selector expression to match elements against. @@ -1841,7 +1841,7 @@ $( "#stop" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ click(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "click" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1891,7 +1891,7 @@ $( "p" ).click(function() { $( "p" ).click(); ``` */ - click(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + click(handler?: JQuery.EventHandler | false): this; /** * Create a deep copy of the set of matched elements. * @param withDataAndEvents A Boolean indicating whether event handlers and data should be copied along with the elements. The @@ -2079,7 +2079,7 @@ $( "#frameDemo" ).contents().find( "a" ).css( "background-color", "#BADA55" ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ contextmenu(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "contextmenu" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -2133,7 +2133,7 @@ div.contextmenu(function() { ``` */ - contextmenu(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + contextmenu(handler?: JQuery.EventHandler | false): this; /** * Set one or more CSS properties for the set of matched elements. * @param propertyName A CSS property name. @@ -2594,7 +2594,7 @@ $( "button" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ dblclick(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "dblclick" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -2648,7 +2648,7 @@ divdbl.dblclick(function() { ``` */ - dblclick(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + dblclick(handler?: JQuery.EventHandler | false): this; /** * Set a timer to delay execution of subsequent items in the queue. * @param duration An integer indicating the number of milliseconds to delay execution of the next item in the queue. @@ -2716,7 +2716,7 @@ $( "button" ).click(function() { delegate(selector: JQuery.Selector, eventType: string, eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. * @param selector A selector to filter the elements that trigger the event. @@ -2830,7 +2830,7 @@ $( "button" ).click(function() { */ delegate(selector: JQuery.Selector, eventType: string, - handler: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + handler: JQuery.EventHandler | false): this; /** * Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. * @param selector A selector to filter the elements that trigger the event. @@ -2844,7 +2844,7 @@ $( "button" ).click(function() { * **Solution**: Change the method call to use `.on()` or `.off()`, the documentation for the old methods include specific instructions. In general, the `.bind()` and `.unbind()` methods can be renamed directly to `.on()` and `.off()` respectively since the argument orders are identical. */ delegate(selector: JQuery.Selector, - events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>): this; + events: JQuery.PlainObject | false>): this; /** * Execute the next function on the queue for the matched elements. * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. @@ -4264,7 +4264,7 @@ $( "p span" ).first().addClass( "highlight" ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focus(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "focus" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -4316,7 +4316,7 @@ $( document ).ready(function() { }); ``` */ - focus(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + focus(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "focusin" event. * @param eventData An object containing data that will be passed to the event handler. @@ -4330,7 +4330,7 @@ $( document ).ready(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focusin(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "focusin" event. * @param handler A function to execute each time the event is triggered. @@ -4370,7 +4370,7 @@ $( "p" ).focusin(function() { ``` */ - focusin(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + focusin(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "focusout" JavaScript event. * @param eventData An object containing data that will be passed to the event handler. @@ -4384,7 +4384,7 @@ $( "p" ).focusin(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focusout(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "focusout" JavaScript event. * @param handler A function to execute each time the event is triggered. @@ -4445,7 +4445,7 @@ $( "p" ) ``` */ - focusout(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + focusout(handler?: JQuery.EventHandler | false): this; /** * Retrieve one of the elements matched by the jQuery object. * @param index A zero-based integer indicating which element to retrieve. @@ -5018,8 +5018,8 @@ $( "li" ) */ // HACK: The type parameter T is not used but ensures the 'event' callback parameter is typed correctly. // tslint:disable-next-line:no-unnecessary-generics - hover(handlerInOut: JQuery.EventHandler | JQuery.EventHandlerBase> | false, - handlerOut?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + hover(handlerInOut: JQuery.EventHandler | false, + handlerOut?: JQuery.EventHandler | false): this; /** * Set the HTML contents of each element in the set of matched elements. * @param htmlString_function _@param_ `htmlString_function` @@ -5833,7 +5833,7 @@ $( "li" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keydown(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -5905,7 +5905,7 @@ $( "#other" ).click(function() { ``` */ - keydown(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + keydown(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -5919,7 +5919,7 @@ $( "#other" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keypress(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -5991,7 +5991,7 @@ $( "#other" ).click(function() { ``` */ - keypress(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + keypress(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6005,7 +6005,7 @@ $( "#other" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keyup(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6078,7 +6078,7 @@ $( "#other").click(function() { ``` */ - keyup(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + keyup(handler?: JQuery.EventHandler | false): this; /** * Reduce the set of matched elements to the final one in the set. * @see \`{@link https://api.jquery.com/last/ }\` @@ -6367,7 +6367,7 @@ $( "input" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mousedown(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6405,7 +6405,7 @@ $( "p" ) ``` */ - mousedown(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mousedown(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6419,7 +6419,7 @@ $( "p" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseenter(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. * @param handler A function to execute each time the event is triggered. @@ -6500,7 +6500,7 @@ $( "div.enterleave" ) ``` */ - mouseenter(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mouseenter(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6514,7 +6514,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseleave(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. * @param handler A function to execute each time the event is triggered. @@ -6593,7 +6593,7 @@ $( "div.enterleave" ) ``` */ - mouseleave(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mouseleave(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6607,7 +6607,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mousemove(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6671,7 +6671,7 @@ $( "div" ).mousemove(function( event ) { ``` */ - mousemove(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mousemove(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6685,7 +6685,7 @@ $( "div" ).mousemove(function( event ) { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseout(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6766,7 +6766,7 @@ $( "div.enterleave" ) ``` */ - mouseout(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mouseout(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6780,7 +6780,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseover(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6861,7 +6861,7 @@ $( "div.enterleave" ) ``` */ - mouseover(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mouseover(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6875,7 +6875,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseup(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6913,7 +6913,7 @@ $( "p" ) ``` */ - mouseup(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + mouseup(handler?: JQuery.EventHandler | false): this; /** * Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector. * @param selector A string containing a selector expression to match elements against. @@ -7471,7 +7471,7 @@ $( "*", document.body ).click(function( event ) { on(events: string, selector: JQuery.Selector | null, data: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7549,7 +7549,7 @@ $( "body" ).on( "click", "a", function( event ) { */ on(events: string, selector: JQuery.Selector, - handler: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + handler: JQuery.EventHandler | false): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7631,7 +7631,7 @@ $( "p" ).on( "click", { foo: "bar" }, myHandler ); */ on(events: string, data: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7744,7 +7744,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { ``` */ on(events: string, - handler: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + handler: JQuery.EventHandler | false): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7849,7 +7849,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>, + on(events: JQuery.PlainObject | false>, selector: JQuery.Selector | null, data: TData): this; /** @@ -7861,7 +7861,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>, + on(events: JQuery.PlainObject | false>, // tslint:disable-next-line:unified-signatures selector: JQuery.Selector): this; /** @@ -7872,7 +7872,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>, + on(events: JQuery.PlainObject | false>, data: TData): this; /** * Attach an event handler function for one or more events to the selected elements. @@ -7922,7 +7922,7 @@ $( "div.test" ).on({ ``` */ - on(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>): this; + on(events: JQuery.PlainObject | false>): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7936,7 +7936,7 @@ $( "div.test" ).on({ one(events: string, selector: JQuery.Selector | null, data: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7949,7 +7949,7 @@ $( "div.test" ).on({ */ one(events: string, selector: JQuery.Selector, - handler: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + handler: JQuery.EventHandler | false): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7960,7 +7960,7 @@ $( "div.test" ).on({ */ one(events: string, data: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -8050,7 +8050,7 @@ $(".target").one("click mouseenter", function() { ``` */ one(events: string, - handler: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + handler: JQuery.EventHandler | false): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -8061,7 +8061,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>, + one(events: JQuery.PlainObject | false>, selector: JQuery.Selector | null, data: TData): this; /** @@ -8073,7 +8073,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>, + one(events: JQuery.PlainObject | false>, // tslint:disable-next-line:unified-signatures selector: JQuery.Selector): this; /** @@ -8084,7 +8084,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>, + one(events: JQuery.PlainObject | false>, data: TData): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. @@ -8093,7 +8093,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | JQuery.EventHandlerBase> | false>): this; + one(events: JQuery.PlainObject | false>): this; /** * Set the CSS outer height of each element in the set of matched elements. * @param value_function _@param_ `value_function` @@ -9851,7 +9851,7 @@ $( "button" ).on( "click", function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ resize(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -9869,7 +9869,7 @@ $( window ).resize(function() { }); ``` */ - resize(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + resize(handler?: JQuery.EventHandler | false): this; /** * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -9883,7 +9883,7 @@ $( window ).resize(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ scroll(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -9933,7 +9933,7 @@ $( window ).scroll(function() { ``` */ - scroll(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + scroll(handler?: JQuery.EventHandler | false): this; /** * Set the current horizontal position of the scroll bar for each of the set of matched elements. * @param value An integer indicating the new position to set the scroll bar to. @@ -10107,7 +10107,7 @@ $( "p:last" ).text( "scrollTop:" + p.scrollTop() ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ select(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "select" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -10156,7 +10156,7 @@ $( ":input" ).select(function() { $( "input" ).select(); ``` */ - select(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + select(handler?: JQuery.EventHandler | false): this; /** * Encode a set of form elements as a string for submission. * @see \`{@link https://api.jquery.com/serialize/ }\` @@ -11127,7 +11127,7 @@ $( "#toggle" ).on( "click", function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ submit(eventData: TData, - handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + handler: JQuery.EventHandler): this; /** * Bind an event handler to the "submit" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -11196,7 +11196,7 @@ $( "form" ).submit(function() { $( "form:first" ).submit(); ``` */ - submit(handler?: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; + submit(handler?: JQuery.EventHandler | false): this; /** * Set the content of each element in the set of matched elements to the specified text. * @param text_function _@param_ `text_function` diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index eba206f323..4f848cc7bb 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -3883,8 +3883,6 @@ function JQuery() { function events() { // [bind() overloads] https://github.com/jquery/api.jquery.com/issues/1048 function bind() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').bind('myEvent', 'myData', function(event) { // $ExpectType HTMLElement @@ -3893,14 +3891,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').bind('myEvent', 'myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').bind('myEvent', function(event) { // $ExpectType HTMLElement @@ -3909,14 +3899,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').bind('myEvent', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').bind('myEvent', false); @@ -3928,12 +3910,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }); @@ -3945,8 +3921,6 @@ function JQuery() { } function delegate() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('table').delegate('td', 'myEvent', 'myData', function(event) { // $ExpectType HTMLElement @@ -3955,14 +3929,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').delegate('td', 'myEvent', 'myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').delegate('td', 'myEvent', function(event) { // $ExpectType HTMLElement @@ -3971,14 +3937,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').delegate('td', 'myEvent', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').delegate('td', 'myEvent', false); @@ -3990,38 +3948,20 @@ function JQuery() { // $ExpectType Event event; }, - myEvent2: false, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - } + myEvent2: false }); } function off() { - function defaultContext_defaultData(this: HTMLElement, event: JQuery.Event) { } + function defaultData(this: HTMLElement, event: JQuery.Event) { } - function defaultContext_customData(this: HTMLElement, event: JQuery.Event) { } - - function customContext_defaultData(this: J1, event: JQuery.Event) { } - - function customContext_customData(this: J1, event: JQuery.Event) { } - - interface J1 { kind: 'J1'; } + function customData(this: HTMLElement, event: JQuery.Event) { } // $ExpectType JQuery - $('table').off('myEvent', 'td', defaultContext_defaultData); + $('table').off('myEvent', 'td', defaultData); // $ExpectType JQuery - $('table').off('myEvent', 'td', defaultContext_customData); - - // $ExpectType JQuery - $('table').off('myEvent', 'td', customContext_defaultData); - - // $ExpectType JQuery - $('table').off('myEvent', 'td', customContext_customData); + $('table').off('myEvent', 'td', customData); // $ExpectType JQuery $('table').off('myEvent', 'td', false); @@ -4030,16 +3970,10 @@ function JQuery() { $('table').off('myEvent', 'td'); // $ExpectType JQuery - $('table').off('myEvent', defaultContext_defaultData); + $('table').off('myEvent', defaultData); // $ExpectType JQuery - $('table').off('myEvent', defaultContext_customData); - - // $ExpectType JQuery - $('table').off('myEvent', customContext_defaultData); - - // $ExpectType JQuery - $('table').off('myEvent', customContext_customData); + $('table').off('myEvent', customData); // $ExpectType JQuery $('table').off('myEvent', false); @@ -4050,19 +3984,15 @@ function JQuery() { // $ExpectType JQuery $('table').off({ myEvent1: false, - defaultContext_defaultData, - defaultContext_customData, - customContext_defaultData, - customContext_customData + defaultData, + customData }, 'td'); // $ExpectType JQuery $('table').off({ myEvent1: false, - defaultContext_defaultData, - defaultContext_customData, - customContext_defaultData, - customContext_customData + defaultData, + customData }); // $ExpectType JQuery @@ -4073,8 +4003,6 @@ function JQuery() { } function on() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('table').on('myEvent', 'td', 'myData', function(event) { // $ExpectType HTMLElement @@ -4091,14 +4019,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', 'td', 'myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', null, 'myData', function(event) { // $ExpectType HTMLElement @@ -4115,14 +4035,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', null, 'myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', 'td', function(event) { // $ExpectType HTMLElement @@ -4139,14 +4051,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', 'td', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', 'td', false); @@ -4166,14 +4070,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', 3, function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', function(event) { // $ExpectType HTMLElement @@ -4214,14 +4110,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', false); @@ -4233,12 +4121,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, 'td', 'myData'); @@ -4250,12 +4132,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, null, 'myData'); @@ -4267,12 +4143,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, 'td'); @@ -4284,12 +4154,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, 3); @@ -4301,19 +4165,11 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }); } function one() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('table').one('myEvent', 'td', 'myData', function(event) { // $ExpectType HTMLElement @@ -4322,14 +4178,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', 'td', 'myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', null, 'myData', function(event) { // $ExpectType HTMLElement @@ -4338,14 +4186,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', null, 'myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', 'td', function(event) { // $ExpectType HTMLElement @@ -4354,14 +4194,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', 'td', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', 'td', false); @@ -4373,14 +4205,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', 3, function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', function(event) { // $ExpectType HTMLElement @@ -4389,14 +4213,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', false); @@ -4408,12 +4224,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, 'td', 'myData'); @@ -4425,12 +4235,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, null, 'myData'); @@ -4442,12 +4246,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, 'td'); @@ -4459,12 +4257,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }, 3); @@ -4476,12 +4268,6 @@ function JQuery() { this; // $ExpectType Event event; - }, - myEvent3(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; } }); } @@ -4551,27 +4337,15 @@ function JQuery() { } function unbind() { - function defaultContext_defaultData(this: HTMLElement, event: JQuery.Event) { } + function defaultData(this: HTMLElement, event: JQuery.Event) { } - function defaultContext_customData(this: HTMLElement, event: JQuery.Event) { } - - function customContext_defaultData(this: J1, event: JQuery.Event) { } - - function customContext_customData(this: J1, event: JQuery.Event) { } - - interface J1 { kind: 'J1'; } + function customData(this: HTMLElement, event: JQuery.Event) { } // $ExpectType JQuery - $('p').unbind('myEvent', defaultContext_defaultData); + $('p').unbind('myEvent', defaultData); // $ExpectType JQuery - $('p').unbind('myEvent', defaultContext_customData); - - // $ExpectType JQuery - $('p').unbind('myEvent', customContext_defaultData); - - // $ExpectType JQuery - $('p').unbind('myEvent', customContext_customData); + $('p').unbind('myEvent', customData); // $ExpectType JQuery $('p').unbind('myEvent', false); @@ -4587,27 +4361,15 @@ function JQuery() { } function undelegate() { - function defaultContext_defaultData(this: HTMLElement, event: JQuery.Event) { } + function defaultData(this: HTMLElement, event: JQuery.Event) { } - function defaultContext_customData(this: HTMLElement, event: JQuery.Event) { } - - function customContext_defaultData(this: J1, event: JQuery.Event) { } - - function customContext_customData(this: J1, event: JQuery.Event) { } - - interface J1 { kind: 'J1'; } + function customData(this: HTMLElement, event: JQuery.Event) { } // $ExpectType JQuery - $('table').undelegate('td', 'click', defaultContext_defaultData); + $('table').undelegate('td', 'click', defaultData); // $ExpectType JQuery - $('table').undelegate('td', 'click', defaultContext_customData); - - // $ExpectType JQuery - $('table').undelegate('td', 'click', customContext_defaultData); - - // $ExpectType JQuery - $('table').undelegate('td', 'click', customContext_customData); + $('table').undelegate('td', 'click', customData); // $ExpectType JQuery $('table').undelegate('td', 'click', false); @@ -4618,10 +4380,8 @@ function JQuery() { // $ExpectType JQuery $('table').undelegate('td', { myEvent1: false, - defaultContext_defaultData, - defaultContext_customData, - customContext_defaultData, - customContext_customData + defaultData, + customData }); // $ExpectType JQuery @@ -4632,8 +4392,6 @@ function JQuery() { } function blur() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').blur('myData', function(event) { // $ExpectType HTMLElement @@ -4642,14 +4400,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').blur('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').blur(function(event) { // $ExpectType HTMLElement @@ -4658,14 +4408,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').blur(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').blur(false); @@ -4674,8 +4416,6 @@ function JQuery() { } function change() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').change('myData', function(event) { // $ExpectType HTMLElement @@ -4684,14 +4424,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').change('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').change(function(event) { // $ExpectType HTMLElement @@ -4700,14 +4432,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').change(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').change(false); @@ -4716,8 +4440,6 @@ function JQuery() { } function click() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').click('myData', function(event) { // $ExpectType HTMLElement @@ -4726,14 +4448,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').click('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').click(function(event) { // $ExpectType HTMLElement @@ -4742,14 +4456,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').click(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').click(false); @@ -4758,8 +4464,6 @@ function JQuery() { } function contextmenu() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').contextmenu('myData', function(event) { // $ExpectType HTMLElement @@ -4768,14 +4472,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').contextmenu('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').contextmenu(function(event) { // $ExpectType HTMLElement @@ -4784,14 +4480,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').contextmenu(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').contextmenu(false); @@ -4800,8 +4488,6 @@ function JQuery() { } function dblclick() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').dblclick('myData', function(event) { // $ExpectType HTMLElement @@ -4810,14 +4496,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').dblclick('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').dblclick(function(event) { // $ExpectType HTMLElement @@ -4826,14 +4504,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').dblclick(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').dblclick(false); @@ -4842,8 +4512,6 @@ function JQuery() { } function focus() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').focus('myData', function(event) { // $ExpectType HTMLElement @@ -4852,14 +4520,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').focus('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').focus(function(event) { // $ExpectType HTMLElement @@ -4868,14 +4528,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').focus(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').focus(false); @@ -4884,8 +4536,6 @@ function JQuery() { } function focusin() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').focusin('myData', function(event) { // $ExpectType HTMLElement @@ -4894,14 +4544,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').focusin('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').focusin(function(event) { // $ExpectType HTMLElement @@ -4910,14 +4552,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').focusin(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').focusin(false); @@ -4926,8 +4560,6 @@ function JQuery() { } function focusout() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').focusout('myData', function(event) { // $ExpectType HTMLElement @@ -4936,14 +4568,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').focusout('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').focusout(function(event) { // $ExpectType HTMLElement @@ -4952,14 +4576,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').focusout(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').focusout(false); @@ -4968,8 +4584,6 @@ function JQuery() { } function keydown() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').keydown('myData', function(event) { // $ExpectType HTMLElement @@ -4978,14 +4592,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').keydown('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').keydown(function(event) { // $ExpectType HTMLElement @@ -4994,14 +4600,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').keydown(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').keydown(false); @@ -5010,8 +4608,6 @@ function JQuery() { } function keypress() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').keypress('myData', function(event) { // $ExpectType HTMLElement @@ -5020,14 +4616,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').keypress('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').keypress(function(event) { // $ExpectType HTMLElement @@ -5036,14 +4624,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').keypress(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').keypress(false); @@ -5052,8 +4632,6 @@ function JQuery() { } function keyup() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').keyup('myData', function(event) { // $ExpectType HTMLElement @@ -5062,14 +4640,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').keyup('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').keyup(function(event) { // $ExpectType HTMLElement @@ -5078,14 +4648,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').keyup(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').keyup(false); @@ -5094,8 +4656,6 @@ function JQuery() { } function mousedown() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mousedown('myData', function(event) { // $ExpectType HTMLElement @@ -5104,14 +4664,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mousedown('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mousedown(function(event) { // $ExpectType HTMLElement @@ -5120,14 +4672,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mousedown(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mousedown(false); @@ -5136,8 +4680,6 @@ function JQuery() { } function mouseenter() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mouseenter('myData', function(event) { // $ExpectType HTMLElement @@ -5146,14 +4688,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseenter('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseenter(function(event) { // $ExpectType HTMLElement @@ -5162,14 +4696,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseenter(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseenter(false); @@ -5178,8 +4704,6 @@ function JQuery() { } function mouseleave() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mouseleave('myData', function(event) { // $ExpectType HTMLElement @@ -5188,14 +4712,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseleave('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseleave(function(event) { // $ExpectType HTMLElement @@ -5204,14 +4720,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseleave(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseleave(false); @@ -5220,8 +4728,6 @@ function JQuery() { } function mousemove() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mousemove('myData', function(event) { // $ExpectType HTMLElement @@ -5230,14 +4736,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mousemove('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mousemove(function(event) { // $ExpectType HTMLElement @@ -5246,14 +4744,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mousemove(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mousemove(false); @@ -5262,8 +4752,6 @@ function JQuery() { } function mouseout() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mouseout('myData', function(event) { // $ExpectType HTMLElement @@ -5272,14 +4760,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseout('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseout(function(event) { // $ExpectType HTMLElement @@ -5288,14 +4768,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseout(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseout(false); @@ -5304,8 +4776,6 @@ function JQuery() { } function mouseover() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mouseover('myData', function(event) { // $ExpectType HTMLElement @@ -5314,14 +4784,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseover('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseover(function(event) { // $ExpectType HTMLElement @@ -5330,14 +4792,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseover(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseover(false); @@ -5346,8 +4800,6 @@ function JQuery() { } function mouseup() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').mouseup('myData', function(event) { // $ExpectType HTMLElement @@ -5356,14 +4808,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseup('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseup(function(event) { // $ExpectType HTMLElement @@ -5372,14 +4816,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').mouseup(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').mouseup(false); @@ -5388,8 +4824,6 @@ function JQuery() { } function resize() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').resize('myData', function(event) { // $ExpectType HTMLElement @@ -5398,14 +4832,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').resize('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').resize(function(event) { // $ExpectType HTMLElement @@ -5414,14 +4840,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').resize(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').resize(false); @@ -5430,8 +4848,6 @@ function JQuery() { } function scroll() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').scroll('myData', function(event) { // $ExpectType HTMLElement @@ -5440,14 +4856,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').scroll('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').scroll(function(event) { // $ExpectType HTMLElement @@ -5456,14 +4864,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').scroll(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').scroll(false); @@ -5472,8 +4872,6 @@ function JQuery() { } function select() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').select('myData', function(event) { // $ExpectType HTMLElement @@ -5482,14 +4880,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').select('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').select(function(event) { // $ExpectType HTMLElement @@ -5498,14 +4888,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').select(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').select(false); @@ -5514,8 +4896,6 @@ function JQuery() { } function submit() { - interface J1 { kind: 'J1'; } - // $ExpectType JQuery $('p').submit('myData', function(event) { // $ExpectType HTMLElement @@ -5524,14 +4904,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').submit('myData', function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').submit(function(event) { // $ExpectType HTMLElement @@ -5540,14 +4912,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').submit(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').submit(false); @@ -5556,9 +4920,6 @@ function JQuery() { } function hover() { - interface J1 { kind: 'J1'; } - interface J2 { kind: 'J2'; } - // $ExpectType JQuery $('p').hover(function(event) { // $ExpectType HTMLElement @@ -5572,59 +4933,12 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').hover(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }, function(event) { - // $ExpectType HTMLElement - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').hover(function(event) { // $ExpectType HTMLElement this; // $ExpectType Event event; - }, function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - - // $ExpectType JQuery - $('p').hover(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }, function(this: J2, event) { - // $ExpectType J2 - this; - // $ExpectType Event - event; - }); - - // $ExpectType JQuery - $('p').hover(function(event) { - // $ExpectType HTMLElement - this; - // $ExpectType Event - event; - }, false); - - // $ExpectType JQuery - $('p').hover(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; }, false); // $ExpectType JQuery @@ -5635,14 +4949,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').hover(false, function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').hover(false, false); @@ -5654,14 +4960,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').hover(function(this: J1, event) { - // $ExpectType J1 - this; - // $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').hover(false); } From f13af8beb0b54f71d8a070c99fdf76cf5601433b Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Wed, 24 Oct 2018 08:38:23 -0400 Subject: [PATCH 078/792] [jquery] Improve declaration of Events API. * Introduced the concept of a triggered event. A triggered event is a jQuery event that has been triggered (either manually by `.trigger()` or `.triggerHandler()`, or automatically by the user agent). Many properties on an event are not set until it has been triggered. Triggered events are now represented by `JQuery.TriggeredEvent`. `JQuery.Event` represents the object returned from the `jQuery.Event` constructor and serves as the base type for all jQuery events. * Added a type parameter for `currentTarget` (`TCurrentTarget`). Previously, `currentTarget` was set to the type of `delegateTarget`. This was only correct for events received from directly bound event handlers. This allows delegate bound event handlers to specify the correct type of `currentTarget`. * Added a type parameter for `target` (`TTarget`). Previously, `target` was set to the type of `delegateTarget`. This was not always correct. For delegate bound event handlers, `target` can be `delegateTarget` or any of its descendents. The exact type of `target` cannot be known until run time, so consumers should use a type assertion. * Changed methods that bind event handlers to more accurately reflect the event object received through the callback. Both direct and delegate binding are now properly handled. This also includes a framework for providing more specific events for known event types. --- types/jquery/JQuery.d.ts | 338 +++++++++++----- types/jquery/jquery-tests.ts | 221 +++++++---- types/jquery/misc.d.ts | 588 ++++++++++++++++------------ types/jquery/test/example-tests.ts | 18 +- types/jquery/test/learn-tests.ts | 2 +- types/jquery/test/longdesc-tests.ts | 4 +- 6 files changed, 716 insertions(+), 455 deletions(-) diff --git a/types/jquery/JQuery.d.ts b/types/jquery/JQuery.d.ts index 70cfaa0e03..f9a06328e7 100644 --- a/types/jquery/JQuery.d.ts +++ b/types/jquery/JQuery.d.ts @@ -530,7 +530,10 @@ $( document ).ajaxComplete(function( event, request, settings ) { }); ``` */ - ajaxComplete(handler: (this: Document, event: JQuery.Event, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings) => void | false): this; + ajaxComplete(handler: (this: Document, + event: JQuery.TriggeredEvent, + jqXHR: JQuery.jqXHR, + ajaxOptions: JQuery.AjaxSettings) => void | false): this; /** * Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event. * @param handler The function to be invoked. @@ -543,7 +546,11 @@ $( document ).ajaxError(function( event, request, settings ) { }); ``` */ - ajaxError(handler: (this: Document, event: JQuery.Event, jqXHR: JQuery.jqXHR, ajaxSettings: JQuery.AjaxSettings, thrownError: string) => void | false): this; + ajaxError(handler: (this: Document, + event: JQuery.TriggeredEvent, + jqXHR: JQuery.jqXHR, + ajaxSettings: JQuery.AjaxSettings, + thrownError: string) => void | false): this; /** * Attach a function to be executed before an Ajax request is sent. This is an Ajax Event. * @param handler The function to be invoked. @@ -556,7 +563,10 @@ $( document ).ajaxSend(function( event, request, settings ) { }); ``` */ - ajaxSend(handler: (this: Document, event: JQuery.Event, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings) => void | false): this; + ajaxSend(handler: (this: Document, + event: JQuery.TriggeredEvent, + jqXHR: JQuery.jqXHR, + ajaxOptions: JQuery.AjaxSettings) => void | false): this; /** * Register a handler to be called when the first Ajax request begins. This is an Ajax Event. * @param handler The function to be invoked. @@ -595,7 +605,11 @@ $( document ).ajaxSuccess(function( event, request, settings ) { }); ``` */ - ajaxSuccess(handler: (this: Document, event: JQuery.Event, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings, data: JQuery.PlainObject) => void | false): this; + ajaxSuccess(handler: (this: Document, + event: JQuery.TriggeredEvent, + jqXHR: JQuery.jqXHR, + ajaxOptions: JQuery.AjaxSettings, + data: JQuery.PlainObject) => void | false): this; /** * Perform a custom animation of a set of CSS properties. * @param properties An object of CSS properties and values that the animation will move toward. @@ -1329,9 +1343,12 @@ $( "p" ).before( $( "b" ) ); * * **Solution**: Change the method call to use `.on()` or `.off()`, the documentation for the old methods include specific instructions. In general, the `.bind()` and `.unbind()` methods can be renamed directly to `.on()` and `.off()` respectively since the argument orders are identical. */ - bind(eventType: string, - eventData: TData, - handler: JQuery.EventHandler): this; + bind( + eventType: TType, + eventData: TData, + handler: JQuery.TypeEventHandler + ): this; /** * Attach a handler to an event for the elements. * @param eventType A string containing one or more DOM event types, such as "click" or "submit," or custom event names. @@ -1458,8 +1475,13 @@ $( "button" ).click(function() { ``` */ - bind(eventType: string, - handler_preventBubble: JQuery.EventHandler | false | null | undefined): this; + bind( + eventType: TType, + handler_preventBubble: JQuery.TypeEventHandler | + false | + null | + undefined + ): this; /** * Attach a handler to an event for the elements. * @param events An object containing one or more DOM event types and functions to execute for them. @@ -1485,7 +1507,7 @@ $( "div.test" ).bind({ }); ``` */ - bind(events: JQuery.PlainObject | false>): this; + bind(events: JQuery.TypeEventHandlers): this; /** * Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -2713,10 +2735,13 @@ $( "button" ).click(function() { * * **Solution**: Change the method call to use `.on()` or `.off()`, the documentation for the old methods include specific instructions. In general, the `.bind()` and `.unbind()` methods can be renamed directly to `.on()` and `.off()` respectively since the argument orders are identical. */ - delegate(selector: JQuery.Selector, - eventType: string, - eventData: TData, - handler: JQuery.EventHandler): this; + delegate( + selector: JQuery.Selector, + eventType: TType, + eventData: TData, + handler: JQuery.TypeEventHandler + ): this; /** * Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. * @param selector A selector to filter the elements that trigger the event. @@ -2828,9 +2853,12 @@ $( "button" ).click(function() { ``` */ - delegate(selector: JQuery.Selector, - eventType: string, - handler: JQuery.EventHandler | false): this; + delegate( + selector: JQuery.Selector, + eventType: TType, + handler: JQuery.TypeEventHandler | + false + ): this; /** * Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. * @param selector A selector to filter the elements that trigger the event. @@ -2844,7 +2872,8 @@ $( "button" ).click(function() { * **Solution**: Change the method call to use `.on()` or `.off()`, the documentation for the old methods include specific instructions. In general, the `.bind()` and `.unbind()` methods can be renamed directly to `.on()` and `.off()` respectively since the argument orders are identical. */ delegate(selector: JQuery.Selector, - events: JQuery.PlainObject | false>): this; + events: JQuery.TypeEventHandlers + ): this; /** * Execute the next function on the queue for the matched elements. * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. @@ -7245,7 +7274,10 @@ $( "body" ).on( "click", "p", foo ); $( "body" ).off( "click", "p", foo ); ``` */ - off(events: string, selector: JQuery.Selector, handler: JQuery.EventHandlerBase> | false): this; + off(events: string, + selector: JQuery.Selector, + handler: JQuery.TypeEventHandler | + false): this; /** * Remove an event handler. * @param events One or more space-separated event types and optional namespaces, or just namespaces, such as @@ -7275,7 +7307,10 @@ $( "form" ).on( "keypress.validator", "input[type='text']", validate ); $( "form" ).off( ".validator" ); ``` */ - off(events: string, selector_handler?: JQuery.Selector | JQuery.EventHandlerBase> | false): this; + off(events: string, + selector_handler?: JQuery.Selector | + JQuery.TypeEventHandler | + false): this; /** * Remove an event handler. * @param events An object where the string keys represent one or more space-separated event types and optional @@ -7284,7 +7319,8 @@ $( "form" ).off( ".validator" ); * @see \`{@link https://api.jquery.com/off/ }\` * @since 1.7 */ - off(events: JQuery.PlainObject> | false>, selector?: JQuery.Selector): this; + off(events: JQuery.TypeEventHandlers, + selector?: JQuery.Selector): this; /** * Remove an event handler. * @param event A jQuery.Event object. @@ -7295,7 +7331,7 @@ $( "form" ).off( ".validator" ); $( "p" ).off(); ``` */ - off(event?: JQuery.Event): this; + off(event?: JQuery.TriggeredEvent): this; /** * Set the current coordinates of every element in the set of matched elements, relative to the document. * @param coordinates_function _@param_ `coordinates_function` @@ -7468,10 +7504,30 @@ $( "*", document.body ).click(function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: string, - selector: JQuery.Selector | null, - data: TData, - handler: JQuery.EventHandler): this; + on( + events: TType, + selector: JQuery.Selector, + data: TData, + handler: JQuery.TypeEventHandler + ): this; + /** + * Attach an event handler function for one or more events to the selected elements. + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the + * selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. + * @see \`{@link https://api.jquery.com/on/ }\` + * @since 1.7 + */ + on( + events: TType, + selector: null | undefined, + data: TData, + handler: JQuery.TypeEventHandler + ): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7484,7 +7540,7 @@ $( "*", document.body ).click(function( event ) { * @deprecated ​ Deprecated. Use \`{@link JQuery.Event }\` in place of \`{@link JQueryEventObject }\`. */ on(events: string, - selector: JQuery.Selector | null, + selector: JQuery.Selector | null | undefined, data: any, handler: ((event: JQueryEventObject) => void)): this; /** @@ -7547,14 +7603,41 @@ $( "body" ).on( "click", "a", function( event ) { }); ``` */ - on(events: string, - selector: JQuery.Selector, - handler: JQuery.EventHandler | false): this; + on( + events: TType, + selector: JQuery.Selector, + handler: JQuery.TypeEventHandler | + false + ): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". - * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the - * selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. + * @see \`{@link https://api.jquery.com/on/ }\` + * @since 1.7 + * @example ​ ````Pass data to the event handler, which is specified here by name: +```javascript +function myHandler( event ) { + alert( event.data.foo ); +} +$( "p" ).on( "click", { foo: "bar" }, myHandler ); +``` + */ + on( + events: TType, + data: TData, + handler: JQuery.TypeEventHandler + ): this; + /** + * Attach an event handler function for one or more events to the selected elements. + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector_data _@param_ `selector_data` + *
+ * * `selector` β€” A selector string to filter the descendants of the selected elements that trigger the event. If the + * selector is null or omitted, the event is always triggered when it reaches the selected element.
+ * * `data` β€” Data to be passed to the handler in event.data when an event is triggered. * @param handler A function to execute when the event is triggered. * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 @@ -7609,37 +7692,6 @@ $( "body" ).on( "click", "a", function( event ) { event.preventDefault(); }); ``` - */ - on(events: string, - selector: JQuery.Selector, - // tslint:disable-next-line:unified-signatures - handler: ((event: JQueryEventObject) => void)): this; - /** - * Attach an event handler function for one or more events to the selected elements. - * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". - * @param data Data to be passed to the handler in event.data when an event is triggered. - * @param handler A function to execute when the event is triggered. - * @see \`{@link https://api.jquery.com/on/ }\` - * @since 1.7 - * @example ​ ````Pass data to the event handler, which is specified here by name: -```javascript -function myHandler( event ) { - alert( event.data.foo ); -} -$( "p" ).on( "click", { foo: "bar" }, myHandler ); -``` - */ - on(events: string, - data: TData, - handler: JQuery.EventHandler): this; - /** - * Attach an event handler function for one or more events to the selected elements. - * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". - * @param data Data to be passed to the handler in event.data when an event is triggered. - * @param handler A function to execute when the event is triggered. - * @see \`{@link https://api.jquery.com/on/ }\` - * @since 1.7 - * @deprecated ​ Deprecated. Use \`{@link JQuery.Event }\` in place of \`{@link JQueryEventObject }\`. * @example ​ ````Pass data to the event handler, which is specified here by name: ```javascript function myHandler( event ) { @@ -7649,8 +7701,7 @@ $( "p" ).on( "click", { foo: "bar" }, myHandler ); ``` */ on(events: string, - // tslint:disable-next-line:unified-signatures - data: any, + selector_data: any, handler: ((event: JQueryEventObject) => void)): this; /** * Attach an event handler function for one or more events to the selected elements. @@ -7743,8 +7794,11 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { }); ``` */ - on(events: string, - handler: JQuery.EventHandler | false): this; + on( + events: TType, + handler: JQuery.TypeEventHandler | + false + ): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7837,7 +7891,6 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { ``` */ on(events: string, - // tslint:disable-next-line:unified-signatures handler: ((event: JQueryEventObject) => void)): this; /** * Attach an event handler function for one or more events to the selected elements. @@ -7849,9 +7902,26 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.PlainObject | false>, - selector: JQuery.Selector | null, - data: TData): this; + on( + events: JQuery.TypeEventHandlers, + selector: JQuery.Selector, + data: TData + ): this; + /** + * Attach an event handler function for one or more events to the selected elements. + * @param events An object in which the string keys represent one or more space-separated event types and optional + * namespaces, and the values represent a handler function to be called for the event(s). + * @param selector A selector string to filter the descendants of the selected elements that will call the handler. If + * the selector is null or omitted, the handler is always called when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event occurs. + * @see \`{@link https://api.jquery.com/on/ }\` + * @since 1.7 + */ + on( + events: JQuery.TypeEventHandlers, + selector: null | undefined, + data: TData + ): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -7861,9 +7931,9 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.PlainObject | false>, - // tslint:disable-next-line:unified-signatures - selector: JQuery.Selector): this; + on(events: JQuery.TypeEventHandlers, + selector: JQuery.Selector + ): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -7872,8 +7942,10 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.PlainObject | false>, - data: TData): this; + on( + events: JQuery.TypeEventHandlers, + data: TData + ): this; /** * Attach an event handler function for one or more events to the selected elements. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -7922,7 +7994,7 @@ $( "div.test" ).on({ ``` */ - on(events: JQuery.PlainObject | false>): this; + on(events: JQuery.TypeEventHandlers): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7933,10 +8005,30 @@ $( "div.test" ).on({ * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: string, - selector: JQuery.Selector | null, - data: TData, - handler: JQuery.EventHandler): this; + one( + events: TType, + selector: JQuery.Selector, + data: TData, + handler: JQuery.TypeEventHandler + ): this; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the + * selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. + * @see \`{@link https://api.jquery.com/one/ }\` + * @since 1.7 + */ + one( + events: TType, + selector: null | undefined, + data: TData, + handler: JQuery.TypeEventHandler + ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7947,9 +8039,12 @@ $( "div.test" ).on({ * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: string, + one( + events: TType, selector: JQuery.Selector, - handler: JQuery.EventHandler | false): this; + handler: JQuery.TypeEventHandler | + false + ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -7958,9 +8053,12 @@ $( "div.test" ).on({ * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: string, - data: TData, - handler: JQuery.EventHandler): this; + one( + events: TType, + data: TData, + handler: JQuery.TypeEventHandler + ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -8049,8 +8147,11 @@ $(".target").one("click mouseenter", function() { ``` */ - one(events: string, - handler: JQuery.EventHandler | false): this; + one( + events: TType, + handler: JQuery.TypeEventHandler| + false + ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -8061,9 +8162,26 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | false>, - selector: JQuery.Selector | null, - data: TData): this; + one( + events: JQuery.TypeEventHandlers, + selector: JQuery.Selector, + data: TData + ): this; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * @param events An object in which the string keys represent one or more space-separated event types and optional + * namespaces, and the values represent a handler function to be called for the event(s). + * @param selector A selector string to filter the descendants of the selected elements that will call the handler. If + * the selector is null or omitted, the handler is always called when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event occurs. + * @see \`{@link https://api.jquery.com/one/ }\` + * @since 1.7 + */ + one( + events: JQuery.TypeEventHandlers, + selector: null | undefined, + data: TData + ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -8073,8 +8191,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | false>, - // tslint:disable-next-line:unified-signatures + one(events: JQuery.TypeEventHandlers, selector: JQuery.Selector): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. @@ -8084,8 +8201,10 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | false>, - data: TData): this; + one( + events: JQuery.TypeEventHandlers, + data: TData + ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events An object in which the string keys represent one or more space-separated event types and optional @@ -8093,7 +8212,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.PlainObject | false>): this; + one(events: JQuery.TypeEventHandlers): this; /** * Set the CSS outer height of each element in the set of matched elements. * @param value_function _@param_ `value_function` @@ -11704,7 +11823,7 @@ $( "body" ).trigger({ }); ``` */ - trigger(eventType_event: string | JQuery.Event, extraParameters?: any[] | JQuery.PlainObject | string | number | boolean): this; + trigger(eventType_event: string | JQuery.Event, extraParameters?: any[] | JQuery.PlainObject | string | number | boolean): this; /** * Execute all handlers attached to an element for an event. * @param eventType_event _@param_ `eventType_event` @@ -11747,7 +11866,7 @@ $( "input" ).focus(function() { ``` */ - triggerHandler(eventType_event: string | JQuery.Event, extraParameters?: any[] | JQuery.PlainObject | string | number | boolean): any; + triggerHandler(eventType_event: string | JQuery.Event, extraParameters?: any[] | JQuery.PlainObject | string | number | boolean): any; /** * Remove a previously-attached event handler from the elements. * @param event A string containing one or more DOM event types, such as "click" or "submit," or custom event names. @@ -11815,7 +11934,10 @@ $( "p" ).bind( "click", foo ); // ... Now foo will be called when paragraphs are $( "p" ).unbind( "click", foo ); // ... foo will no longer be called. ``` */ - unbind(event: string, handler: JQuery.EventHandlerBase> | false): this; + unbind(event: string, + handler: JQuery.TypeEventHandler | + false + ): this; /** * Remove a previously-attached event handler from the elements. * @param event A string containing one or more DOM event types, such as "click" or "submit," or custom event names. @@ -11836,7 +11958,7 @@ $( "p" ).unbind(); $( "p" ).unbind( "click" ); ``` */ - unbind(event?: string | JQuery.Event): this; + unbind(event?: string | JQuery.TriggeredEvent): this; /** * Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements. * @param selector A selector which will be used to filter the event results. @@ -11906,12 +12028,18 @@ $( "body" ).delegate( "p", "click", foo ); $( "body" ).undelegate( "p", "click", foo ); ``` */ - undelegate(selector: JQuery.Selector, eventType: string, handler: JQuery.EventHandlerBase> | false): this; + undelegate(selector: JQuery.Selector, + eventType: string, + handler: JQuery.TypeEventHandler | + false + ): this; /** * Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements. * @param selector A selector which will be used to filter the event results. - * @param eventTypes A string containing a JavaScript event type, such as "click" or "keydown" - * An object of one or more event types and previously bound functions to unbind from them. + * @param eventType_events _@param_ `eventType_events` + *
+ * * `eventType` β€” A string containing a JavaScript event type, such as "click" or "keydown"
+ * * `events` β€” An object of one or more event types and previously bound functions to unbind from them. * @see \`{@link https://api.jquery.com/undelegate/ }\` * @since 1.4.2 * @since 1.4.3 @@ -11921,7 +12049,9 @@ $( "body" ).undelegate( "p", "click", foo ); * * **Solution**: Change the method call to use `.on()` or `.off()`, the documentation for the old methods include specific instructions. In general, the `.bind()` and `.unbind()` methods can be renamed directly to `.on()` and `.off()` respectively since the argument orders are identical. */ - undelegate(selector: JQuery.Selector, eventTypes: string | JQuery.PlainObject> | false>): this; + undelegate(selector: JQuery.Selector, + eventType_events: string | + JQuery.TypeEventHandlers): this; /** * Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements. * @param namespace A selector which will be used to filter the event results. diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 4f848cc7bb..b08b48d0b0 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -2430,7 +2430,7 @@ function JQuery() { $(document).ajaxComplete(function(event, jqXHR, ajaxOptions) { // $ExpectType Document this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; // $ExpectType jqXHR jqXHR; @@ -2446,7 +2446,7 @@ function JQuery() { $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) { // $ExpectType Document this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; // $ExpectType jqXHR jqXHR; @@ -2464,7 +2464,7 @@ function JQuery() { $(document).ajaxSend(function(event, jqXHR, ajaxOptions) { // $ExpectType Document this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; // $ExpectType jqXHR jqXHR; @@ -2500,7 +2500,7 @@ function JQuery() { $(document).ajaxSuccess(function(event, jqXHR, ajaxOptions, data) { // $ExpectType Document this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; // $ExpectType jqXHR jqXHR; @@ -3887,7 +3887,7 @@ function JQuery() { $('p').bind('myEvent', 'myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); @@ -3895,45 +3895,45 @@ function JQuery() { $('p').bind('myEvent', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); // $ExpectType JQuery $('p').bind('myEvent', false); + // $ExpectType JQuery + $('p').bind('myEvent', null); + + // $ExpectType JQuery + $('p').bind('myEvent', undefined); + // $ExpectType JQuery $('p').bind({ myEvent1: false, myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }); - - // $ExpectType JQuery - $('p').bind('myEvent', null); - - // $ExpectType JQuery - $('p').bind('myEvent', undefined); - } + } function delegate() { // $ExpectType JQuery $('table').delegate('td', 'myEvent', 'myData', function(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); // $ExpectType JQuery $('table').delegate('td', 'myEvent', function(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); @@ -3942,20 +3942,20 @@ function JQuery() { // $ExpectType JQuery $('table').delegate('td', { - myEvent1(event) { - // $ExpectType HTMLElement + myEvent1: false, + myEvent2(event) { + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; - }, - myEvent2: false + } }); } function off() { - function defaultData(this: HTMLElement, event: JQuery.Event) { } + function defaultData(this: HTMLElement, event: JQuery.TriggeredEvent) { } - function customData(this: HTMLElement, event: JQuery.Event) { } + function customData(this: HTMLElement, event: JQuery.TriggeredEvent) { } // $ExpectType JQuery $('table').off('myEvent', 'td', defaultData); @@ -3995,27 +3995,19 @@ function JQuery() { customData }); + const ev: JQuery.TriggeredEvent = undefined!; // $ExpectType JQuery - $('table').off($.Event('myEvent')); + $('table').off(ev); // $ExpectType JQuery $('table').off(); } function on() { - // $ExpectType JQuery $('table').on('myEvent', 'td', 'myData', function(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event - event; - }); - - // $ExpectType JQuery - $('table').on('myEvent', 'td', 'myData', function(event: JQueryEventObject) { - // $ExpectType HTMLElement - this; - // $ExpectType JQueryEventObject + // $ExpectType TriggeredEvent event; }); @@ -4023,12 +4015,38 @@ function JQuery() { $('table').on('myEvent', null, 'myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', undefined, 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType TriggeredEvent + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', 'td', 'myData', function(event: JQueryEventObject) { + // $ExpectType any + this; + // $ExpectType JQueryEventObject event; }); // $ExpectType JQuery $('table').on('myEvent', null, 'myData', function(event: JQueryEventObject) { + // TODO: Why is this HTMLElement? The callback signature doesn't even have `this` declared. + // $ExpectType HTMLElement + this; + // $ExpectType JQueryEventObject + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', undefined, 'myData', function(event: JQueryEventObject) { + // TODO: Why is this HTMLElement? The callback signature doesn't even have `this` declared. // $ExpectType HTMLElement this; // $ExpectType JQueryEventObject @@ -4037,17 +4055,9 @@ function JQuery() { // $ExpectType JQuery $('table').on('myEvent', 'td', function(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event - event; - }); - - // $ExpectType JQuery - $('table').on('myEvent', 'td', function(event: JQueryEventObject) { - // $ExpectType HTMLElement - this; - // $ExpectType JQueryEventObject + // $ExpectType TriggeredEvent event; }); @@ -4058,7 +4068,15 @@ function JQuery() { $('table').on('myEvent', 3, function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', 'td', function(event: JQueryEventObject) { + // $ExpectType any + this; + // $ExpectType JQueryEventObject event; }); @@ -4074,10 +4092,13 @@ function JQuery() { $('table').on('myEvent', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); + // $ExpectType JQuery + $('table').on('myEvent', false); + // $ExpectType JQuery $('table').on('myEvent', function(event: JQueryEventObject) { // $ExpectType HTMLElement @@ -4110,16 +4131,13 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', false); - // $ExpectType JQuery $('table').on({ myEvent1: false, myEvent2(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }, 'td', 'myData'); @@ -4130,7 +4148,7 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }, null, 'myData'); @@ -4141,7 +4159,18 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent + event; + } + }, undefined, 'myData'); + + // $ExpectType JQuery + $('table').on({ + myEvent1: false, + myEvent2(event) { + // $ExpectType any + this; + // $ExpectType TriggeredEvent event; } }, 'td'); @@ -4152,7 +4181,7 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }, 3); @@ -4163,7 +4192,7 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }); @@ -4172,9 +4201,9 @@ function JQuery() { function one() { // $ExpectType JQuery $('table').one('myEvent', 'td', 'myData', function(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); @@ -4182,15 +4211,23 @@ function JQuery() { $('table').one('myEvent', null, 'myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent + event; + }); + + // $ExpectType JQuery + $('table').one('myEvent', undefined, 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType TriggeredEvent event; }); // $ExpectType JQuery $('table').one('myEvent', 'td', function(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); @@ -4201,7 +4238,7 @@ function JQuery() { $('table').one('myEvent', 3, function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); @@ -4209,7 +4246,7 @@ function JQuery() { $('table').one('myEvent', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; }); @@ -4220,9 +4257,9 @@ function JQuery() { $('table').one({ myEvent1: false, myEvent2(event) { - // $ExpectType HTMLElement + // $ExpectType any this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }, 'td', 'myData'); @@ -4233,7 +4270,7 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }, null, 'myData'); @@ -4244,7 +4281,18 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent + event; + } + }, undefined, 'myData'); + + // $ExpectType JQuery + $('table').one({ + myEvent1: false, + myEvent2(event) { + // $ExpectType any + this; + // $ExpectType TriggeredEvent event; } }, 'td'); @@ -4255,7 +4303,7 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }, 3); @@ -4266,7 +4314,7 @@ function JQuery() { myEvent2(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType TriggeredEvent event; } }); @@ -4337,9 +4385,9 @@ function JQuery() { } function unbind() { - function defaultData(this: HTMLElement, event: JQuery.Event) { } + function defaultData(this: HTMLElement, event: JQuery.TriggeredEvent) { } - function customData(this: HTMLElement, event: JQuery.Event) { } + function customData(this: HTMLElement, event: JQuery.TriggeredEvent) { } // $ExpectType JQuery $('p').unbind('myEvent', defaultData); @@ -4353,17 +4401,18 @@ function JQuery() { // $ExpectType JQuery $('p').unbind('myEvent'); + const ev: JQuery.TriggeredEvent = undefined!; // $ExpectType JQuery - $('p').unbind($.Event('myEvent')); + $('p').unbind(ev); // $ExpectType JQuery $('p').unbind(); } function undelegate() { - function defaultData(this: HTMLElement, event: JQuery.Event) { } + function defaultData(this: HTMLElement, event: JQuery.TriggeredEvent) { } - function customData(this: HTMLElement, event: JQuery.Event) { } + function customData(this: HTMLElement, event: JQuery.TriggeredEvent) { } // $ExpectType JQuery $('table').undelegate('td', 'click', defaultData); @@ -7696,18 +7745,18 @@ function JQuery_Effects() { function JQuery_Event() { function call_signature() { - // $ExpectType Event & Coordinates + // $ExpectType Event & Coordinates $.Event('keydown', $('p').offset()); } function constructor() { - // $ExpectType Event & Coordinates + // $ExpectType Event & Coordinates new $.Event('keydown', $('p').offset()); } // https://stackoverflow.com/questions/49892574/trigger-a-jquery-3-event-with-ctrlkey-set function stackoverflow_49892574() { - const event = $.Event("keydown"); + const event = $.Event("keydown"); event.which = 77; event.ctrlKey = true; $(window).trigger(event); @@ -7727,7 +7776,7 @@ function JQuery_EventExtensions() { data; // $ExpectType string namespaces; - // $ExpectType EventHandler + // $ExpectType EventHandlerBase> eventHandle; return false; @@ -7753,7 +7802,7 @@ function JQuery_EventExtensions() { trigger(event, data) { // $ExpectType EventTarget this; - // $ExpectType Event + // $ExpectType Event event; // $ExpectType any data; @@ -7761,7 +7810,7 @@ function JQuery_EventExtensions() { return false; }, _default(event, data) { - // $ExpectType Event + // $ExpectType TriggeredEvent event; // $ExpectType any data; @@ -7769,7 +7818,7 @@ function JQuery_EventExtensions() { return false; }, handle(event, data) { - // $ExpectType Event & { handleObj: HandleObject; } + // $ExpectType TriggeredEvent & { handleObj: HandleObject; } event; // $ExpectType any data; @@ -7777,7 +7826,7 @@ function JQuery_EventExtensions() { preDispatch(event) { // $ExpectType EventTarget this; - // $ExpectType Event + // $ExpectType Event event; return false; @@ -7785,7 +7834,7 @@ function JQuery_EventExtensions() { postDispatch(event) { // $ExpectType EventTarget this; - // $ExpectType Event + // $ExpectType Event event; } }; diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index 94f7279e63..d966f1b787 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -3981,45 +3981,97 @@ $( "input" ).click(function() { // This should be a class but doesn't work correctly under the JQuery namespace. Event should be an inner class of jQuery. - // Static members + /** + * jQuery's event system normalizes the event object according to W3C standards. The event object is guaranteed to be passed to the event handler (no checks for window.event required). It normalizes the target, relatedTarget, which, metaKey and pageX/Y properties and provides both stopPropagation() and preventDefault() methods. + * + * Those properties are all documented, and accompanied by examples, on the \`{@link http://api.jquery.com/category/events/event-object/ Event object}\` page. + * + * The standard events in the Document Object Model are: `blur`, `focus`, `load`, `resize`, `scroll`, `unload`, `beforeunload`, `click`, `dblclick`, `mousedown`, `mouseup`, `mousemove`, `mouseover`, `mouseout`, `mouseenter`, `mouseleave`, `change`, `select`, `submit`, `keydown`, `keypress`, and `keyup`. Since the DOM event names have predefined meanings for some elements, using them for other purposes is not recommended. jQuery's event model can trigger an event by any name on an element, and it is propagated up the DOM tree to which that element belongs, if any. + * @see \`{@link https://api.jquery.com/category/events/event-object/ }\` + */ interface EventStatic { - // tslint:disable-next-line:no-unnecessary-generics - (event: string, properties?: T): Event & T; - // tslint:disable-next-line:no-unnecessary-generics - new (event: string, properties?: T): Event & T; + /** + * The jQuery.Event constructor is exposed and can be used when calling trigger. The new operator is optional. + * + * Check \`{@link https://api.jquery.com/trigger/ trigger}\`'s documentation to see how to combine it with your own event object. + * @see \`{@link https://api.jquery.com/category/events/event-object/ }\` + * @since 1.6 + * @example +```javascript +//Create a new jQuery.Event object without the "new" operator. +var e = jQuery.Event( "click" ); +​ +// trigger an artificial click event +jQuery( "body" ).trigger( e ); +``` + * @example +```javascript +// Create a new jQuery.Event object with specified event properties. +var e = jQuery.Event( "keydown", { keyCode: 64 } ); +​ +// trigger an artificial keydown event with keyCode 64 +jQuery( "body" ).trigger( e ); +``` + */ + (event: string, properties?: T): Event & T; + /** + * The jQuery.Event constructor is exposed and can be used when calling trigger. The new operator is optional. + * + * Check \`{@link https://api.jquery.com/trigger/ trigger}\`'s documentation to see how to combine it with your own event object. + * @see \`{@link https://api.jquery.com/category/events/event-object/ }\` + * @since 1.6 + * @example +```javascript +//Create a new jQuery.Event object without the "new" operator. +var e = jQuery.Event( "click" ); +​ +// trigger an artificial click event +jQuery( "body" ).trigger( e ); +``` + * @example +```javascript +// Create a new jQuery.Event object with specified event properties. +var e = jQuery.Event( "keydown", { keyCode: 64 } ); +​ +// trigger an artificial keydown event with keyCode 64 +jQuery( "body" ).trigger( e ); +``` + */ + new (event: string, properties?: T): Event & T; } - // Instance members + /** + * jQuery's event system normalizes the event object according to W3C standards. The event object is guaranteed to be passed to the event handler (no checks for window.event required). It normalizes the target, relatedTarget, which, metaKey and pageX/Y properties and provides both stopPropagation() and preventDefault() methods. + * + * Those properties are all documented, and accompanied by examples, on the \`{@link http://api.jquery.com/category/events/event-object/ Event object}\` page. + * + * The standard events in the Document Object Model are: `blur`, `focus`, `load`, `resize`, `scroll`, `unload`, `beforeunload`, `click`, `dblclick`, `mousedown`, `mouseup`, `mousemove`, `mouseover`, `mouseout`, `mouseenter`, `mouseleave`, `change`, `select`, `submit`, `keydown`, `keypress`, and `keyup`. Since the DOM event names have predefined meanings for some elements, using them for other purposes is not recommended. jQuery's event model can trigger an event by any name on an element, and it is propagated up the DOM tree to which that element belongs, if any. + * @see \`{@link https://api.jquery.com/category/events/event-object/ }\` + * @see \`{@link TriggeredEvent }\` + */ interface Event { // region Copied properties // #region Copied properties - // region Event - // #region Event + // Event - bubbles?: boolean; - cancelable?: boolean; - eventPhase?: number; + bubbles: boolean | undefined; + cancelable: boolean | undefined; + eventPhase: number | undefined; - // #endregion + // UIEvent - // region UIEvent - // #region UIEvent + detail: number | undefined; + view: Window | undefined; - detail?: number; - view?: Window; + // MouseEvent - // #endregion - - // region MouseEvent - // #region MouseEvent - - button?: number; - buttons?: number; - clientX?: number; - clientY?: number; - offsetX?: number; - offsetY?: number; + button: number | undefined; + buttons: number | undefined; + clientX: number | undefined; + clientY: number | undefined; + offsetX: number | undefined; + offsetY: number | undefined; /** * The mouse position relative to the left edge of the document. * @see \`{@link https://api.jquery.com/event.pageX/ }\` @@ -4055,7 +4107,7 @@ $( document ).on( "mousemove", function( event ) { ``` */ - pageX: number; + pageX: number | undefined; /** * The mouse position relative to the top edge of the document. * @see \`{@link https://api.jquery.com/event.pageY/ }\` @@ -4091,49 +4143,93 @@ $( document ).on( "mousemove", function( event ) { ``` */ - pageY: number; - screenX?: number; - screenY?: number; + pageY: number | undefined; + screenX: number | undefined; + screenY: number | undefined; /** @deprecated */ - toElement?: Element; + toElement: Element | undefined; - // #endregion + // PointerEvent - // region PointerEvent - // #region PointerEvent + pointerId: number | undefined; + pointerType: string | undefined; - pointerId?: number; - pointerType?: string; - - // #endregion - - // region KeyboardEvent - // #region KeyboardEvent + // KeyboardEvent /** @deprecated */ - char?: string; + char: string | undefined; /** @deprecated */ - charCode?: number; - key?: string; + charCode: number | undefined; + key: string | undefined; /** @deprecated */ - keyCode?: number; + keyCode: number | undefined; - // #endregion + // TouchEvent - // region TouchEvent - // #region TouchEvent + changedTouches: TouchList | undefined; + targetTouches: TouchList | undefined; + touches: TouchList | undefined; - changedTouches?: TouchList; - targetTouches?: TouchList; - touches?: TouchList; + // MouseEvent, KeyboardEvent - // #endregion + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see \`{@link https://api.jquery.com/event.which/ }\` + * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. + * @example ​ ````Log which key was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + * @example ​ ````Log which mouse button was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + */ + which: number | undefined; - // region MouseEvent, KeyboardEvent, TouchEvent - // #region MouseEvent, KeyboardEvent, TouchEvent + // MouseEvent, KeyboardEvent, TouchEvent - altKey?: boolean; - ctrlKey?: boolean; + altKey: boolean | undefined; + ctrlKey: boolean | undefined; /** * Indicates whether the META key was pressed when the event fired. * @see \`{@link https://api.jquery.com/event.metaKey/ }\` @@ -4170,77 +4266,11 @@ $( "#checkMetaKey" ).click(function( event ) { ``` */ - metaKey: boolean; - shiftKey?: boolean; + metaKey: boolean | undefined; + shiftKey: boolean | undefined; // #endregion - // #endregion - - /** - * The namespace specified when the event was triggered. - * @see \`{@link https://api.jquery.com/event.namespace/ }\` - * @since 1.4.3 - * @example ​ ````Determine the event namespace used. -```html - - - - - event.namespace demo - - - -​ - -

-​ - -​ - - -``` - */ - namespace: string; - /** - * The last value returned by an event handler that was triggered by this event, unless the value was undefined. - * @see \`{@link https://api.jquery.com/event.result/ }\` - * @since 1.3 - * @example ​ ````Display previous handler's return value -```html - - - - - event.result demo - - - -​ - -

-​ - -​ - - -``` - */ - result: any; /** * The difference in milliseconds between the time the browser created the event and January 1, 1970. * @see \`{@link https://api.jquery.com/event.timeStamp/ }\` @@ -4297,59 +4327,6 @@ $( "a" ).click(function( event ) { ``` */ type: string; - /** - * For key or mouse events, this property indicates the specific key or button that was pressed. - * @see \`{@link https://api.jquery.com/event.which/ }\` - * @since 1.1.3 - * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. - * @example ​ ````Log which key was depressed. -```html - - - - - event.which demo - - - -​ - -
-​ - -​ - - -``` - * @example ​ ````Log which mouse button was depressed. -```html - - - - - event.which demo - - - -​ - -
-​ - -​ - - -``` - */ - which: number; /** * Returns whether event.preventDefault() was ever called on this event object. * @see \`{@link https://api.jquery.com/event.isDefaultPrevented/ }\` @@ -4542,11 +4519,17 @@ $( "p" ).click(function( event ) { stopPropagation(): void; } - // Generic members - interface Event< - TTarget = EventTarget, - TData = null - > { + // #endregion + + /** + * Base type for jQuery events that have been triggered (including events triggered on plain objects). + */ + interface TriggeredEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends Event { /** * The current DOM element within the event bubbling phase. * @see \`{@link https://api.jquery.com/event.currentTarget/ }\` @@ -4557,51 +4540,8 @@ $( "p" ).click(function( event ) { alert( event.currentTarget === this ); // true }); ``` - */ - currentTarget: TTarget; - /** - * An optional object of data passed to an event method when the current executing handler is bound. - * @see \`{@link https://api.jquery.com/event.data/ }\` - * @since 1.1 - * @example ​ ````Within a for loop, pass the value of i to the .on() method so that the current iteration's value is preserved. -```html - - - - - event.data demo - - - -​ - - - - - -​ -
-​ - -​ - - -``` - */ - data: TData; + */ + currentTarget: TCurrentTarget; /** * The element where the currently-called jQuery event handler was attached. * @see \`{@link https://api.jquery.com/event.delegateTarget/ }\` @@ -4612,21 +4552,8 @@ $( ".box" ).on( "click", "button", function( event ) { $( event.delegateTarget ).css( "background-color", "red" ); }); ``` - */ - delegateTarget: TTarget; - originalEvent: _Event; - /** - * The other DOM element involved in the event, if any. - * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` - * @since 1.1.4 - * @example ​ ````On mouseout of anchors, alert the element type being entered. -```javascript -$( "a" ).mouseout(function( event ) { - alert( event.relatedTarget.nodeName ); // "DIV" -}); -``` - */ - relatedTarget: TTarget | null; + */ + delegateTarget: TDelegateTarget; /** * The DOM element that initiated the event. * @see \`{@link https://api.jquery.com/event.target/ }\` @@ -4704,17 +4631,173 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); ``` - */ + */ target: TTarget; + + /** + * An optional object of data passed to an event method when the current executing handler is bound. + * @see \`{@link https://api.jquery.com/event.data/ }\` + * @since 1.1 + * @example ​ ````Within a for loop, pass the value of i to the .on() method so that the current iteration's value is preserved. +```html + + + + + event.data demo + + + +​ + + + + + +​ +
+​ + +​ + + +``` + */ + data: TData; + + /** + * The namespace specified when the event was triggered. + * @see \`{@link https://api.jquery.com/event.namespace/ }\` + * @since 1.4.3 + * @example ​ ````Determine the event namespace used. +```html + + + + + event.namespace demo + + + +​ + +

+​ + +​ + + +``` + */ + namespace?: string; + /** + * The last value returned by an event handler that was triggered by this event, unless the value was undefined. + * @see \`{@link https://api.jquery.com/event.result/ }\` + * @since 1.3 + * @example ​ ````Display previous handler's return value +```html + + + + + event.result demo + + + +​ + +

+​ + +​ + + +``` + */ + result?: any; } - // #endregion - - interface EventHandler extends EventHandlerBase> { } + interface TypeToTriggeredEventMap< + TDelegateTarget, + TData, + TCurrentTarget, + TTarget + > { + [type: string]: TriggeredEvent; + } // Extra parameters can be passed from trigger() type EventHandlerBase = (this: TContext, t: T, ...args: any[]) => any; + type EventHandler< + TCurrentTarget, + TData = undefined + > = EventHandlerBase>; + + type TypeEventHandler< + TDelegateTarget, + TData, + TCurrentTarget, + TTarget, + TContext, + TType extends keyof TypeToTriggeredEventMap + > = EventHandlerBase[TType]>; + + interface TypeEventHandlers< + TDelegateTarget, + TData, + TCurrentTarget, + TTarget, + TContext + > extends _TypeEventHandlers { + // No idea why it's necessary to include `object` in the union but otherwise TypeScript complains that + // derived types of Event are not assignable to Event. + [type: string]: TypeEventHandler | + false | + undefined | + object; + } + + type _TypeEventHandlers< + TDelegateTarget, + TData, + TCurrentTarget, + TTarget, + TContext + > = { + [TType in keyof TypeToTriggeredEventMap]?: + TypeEventHandler | + false | + object; + }; + // region Event extensions // #region Event extensions @@ -4791,13 +4874,13 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); * The trigger hook is called early in the process of triggering an event, just after the `jQuery.Event` object is constructed and before any handlers have been called. It can process the triggered event in any way, for example by calling `event.stopPropagation()` or `event.preventDefault()` before returning. If the hook returns `false`, jQuery does not perform any further event triggering actions and returns immediately. Otherwise, it performs the normal trigger processing, calling any event handlers for the element and bubbling the event (unless propagation is stopped in advance or `noBubble` was specified for the special event) to call event handlers attached to parent elements. * @see \`{@link https://learn.jquery.com/events/event-extensions/#trigger-function-event-jquery-event-data-object }\` */ - trigger(this: TTarget, event: Event, data: TData): void | false; + trigger(this: TTarget, event: Event, data: TData): void | false; } | { /** * When the `.trigger()` method finishes running all the event handlers for an event, it also looks for and runs any method on the target object by the same name unless of the handlers called `event.preventDefault()`. So, `.trigger( "submit" )` will execute the `submit()` method on the element if one exists. When a `_default` hook is specified, the hook is called just prior to checking for and executing the element's default method. If this hook returns the value `false` the element's default method will be called; otherwise it is not. * @see \`{@link https://learn.jquery.com/events/event-extensions/#_default-function-event-jquery-event-data-object }\` */ - _default(event: Event, data: TData): void | false; + _default(event: TriggeredEvent, data: TData): void | false; } | { /** * jQuery calls a handle hook when the event has occurred and jQuery would normally call the user's event handler specified by `.on()` or another event binding method. If the hook exists, jQuery calls it _instead_ of that event handler, passing it the event and any data passed from `.trigger()` if it was not a native event. The `this` keyword is the DOM element being handled, and `event.handleObj` property has the detailed event information. @@ -4805,11 +4888,11 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); * Based in the information it has, the handle hook should decide whether to call the original handler function which is in `event.handleObj.handler`. It can modify information in the event object before calling the original handler, but _must restore_ that data before returning or subsequent unrelated event handlers may act unpredictably. In most cases, the handle hook should return the result of the original handler, but that is at the discretion of the hook. The handle hook is unique in that it is the only special event function hook that is called under its original special event name when the type is mapped using `bindType` and `delegateType`. For that reason, it is almost always an error to have anything other than a handle hook present if the special event defines a `bindType` and `delegateType`, since those other hooks will never be called. * @see \`{@link https://learn.jquery.com/events/event-extensions/#handle-function-event-jquery-event-data-object }\` */ - handle(this: TTarget, event: Event & { handleObj: HandleObject; }, ...data: TData[]): void; + handle(this: TTarget, event: TriggeredEvent & { handleObj: HandleObject; }, ...data: TData[]): void; } | { - preDispatch(this: TTarget, event: Event): false | void; + preDispatch(this: TTarget, event: Event): false | void; } | { - postDispatch(this: TTarget, event: Event): void; + postDispatch(this: TTarget, event: Event): void; } | { [key: string]: never; }; @@ -4901,7 +4984,6 @@ $( "ul" ).click( handler ).find( "ul" ).hide(); declare const jQuery: JQueryStatic; declare const $: JQueryStatic; -// Used by JQuery.Event type _Event = Event; // region ES5 compatibility diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 7ecb1733a7..673e549c31 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -384,7 +384,7 @@ function examples() { } function bind_2() { - function handler(event: JQuery.Event) { + function handler(event: JQuery.TriggeredEvent) { alert(event.data.foo); } @@ -830,7 +830,7 @@ function examples() { var len = kids.addClass('hilite').length; $('#results span:first').text(len); - $('#results span:last').text(event.target.tagName); + $('#results span:last').text((event.target as Element).tagName); event.preventDefault(); }); @@ -1614,12 +1614,12 @@ function examples() { function event_target_0() { $('body').click(function(event) { - $('#log').html('clicked: ' + event.target.nodeName); + $('#log').html('clicked: ' + (event.target as Node).nodeName); }); } function event_target_1() { - function handler(event: JQuery.Event) { + function handler(event: JQuery.TriggeredEvent) { var target = $(event.target); if (target.is('li')) { target.children().toggle(); @@ -3018,10 +3018,10 @@ function examples() { function jQuery_proxy_0() { var me = { type: 'zombie', - test: function(event: JQuery.Event) { + test: function(event: JQuery.TriggeredEvent) { // Without proxy, `this` would refer to the event target // use event.target to reference that element. - var element = event.target; + var element = event.target as Element; $(element).css('background-color', 'red'); // With proxy, `this` refers to the me object encapsulating @@ -3033,7 +3033,7 @@ function examples() { var you = { type: 'person', - test: function(event: JQuery.Event) { + test: function(event: JQuery.TriggeredEvent) { $('#log').append(this.type + ' '); }, }; @@ -3075,7 +3075,7 @@ function examples() { type: 'dog', // Note that event comes *after* one and two - test: function(one: typeof you, two: typeof they, event: JQuery.Event) { + test: function(one: typeof you, two: typeof they, event: JQuery.TriggeredEvent) { $('#log') // `one` maps to `you`, the 1st additional @@ -3796,7 +3796,7 @@ function examples() { } function on_1() { - function myHandler(event: JQuery.Event) { + function myHandler(event: JQuery.TriggeredEvent) { alert(event.data.foo); } diff --git a/types/jquery/test/learn-tests.ts b/types/jquery/test/learn-tests.ts index 523385b644..b1a0353b4e 100644 --- a/types/jquery/test/learn-tests.ts +++ b/types/jquery/test/learn-tests.ts @@ -35,7 +35,7 @@ function special() { bindType: "click", handle(event) { const handleObj = event.handleObj; - const targetData = jQuery.data(event.target); + const targetData = jQuery.data(event.target as Element); let ret = null; // If a multiple of the click count, run the handler diff --git a/types/jquery/test/longdesc-tests.ts b/types/jquery/test/longdesc-tests.ts index bb3bb4c83c..f3cf559638 100644 --- a/types/jquery/test/longdesc-tests.ts +++ b/types/jquery/test/longdesc-tests.ts @@ -538,7 +538,7 @@ function longdesc() { $('#foo').slideUp(300).delay(800).fadeIn(400); } - function delegate_0(elements: HTMLElement[], selector: string, events: any, data: any, handler: JQuery.EventHandler) { + function delegate_0(elements: HTMLElement[], selector: string, events: string, data: any, handler: JQuery.TypeEventHandler) { // jQuery 1.4.3+ $(elements).delegate(selector, events, data, handler); // jQuery 1.7+ @@ -2016,7 +2016,7 @@ function longdesc() { } function on_3() { - function greet(event: JQuery.Event) { + function greet(event: JQuery.TriggeredEvent) { alert('Hello ' + event.data.name); } From 00c546398c4d3d98655a4bce525a077dd52c83c1 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Wed, 24 Oct 2018 10:26:51 -0400 Subject: [PATCH 079/792] [jquery] Add support for event types that have shorthand methods. --- types/jquery/JQuery.d.ts | 136 ++-- types/jquery/jquery-tests.ts | 197 ++++-- types/jquery/misc.d.ts | 1282 ++++++++++++++++++++++++++++++++++ 3 files changed, 1515 insertions(+), 100 deletions(-) diff --git a/types/jquery/JQuery.d.ts b/types/jquery/JQuery.d.ts index f9a06328e7..83e27c6754 100644 --- a/types/jquery/JQuery.d.ts +++ b/types/jquery/JQuery.d.ts @@ -1521,7 +1521,7 @@ $( "div.test" ).bind({ * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ blur(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1537,7 +1537,8 @@ $( "div.test" ).bind({ $( "p" ).blur(); ``` */ - blur(handler?: JQuery.EventHandler | false): this; + blur(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "change" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -1551,7 +1552,7 @@ $( "p" ).blur(); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ change(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "change" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1610,7 +1611,8 @@ $( "input[type='text']" ).change(function() { }); ``` */ - change(handler?: JQuery.EventHandler | false): this; + change(handler?: JQuery.TypeEventHandler | + false): this; /** * Get the children of each element in the set of matched elements, optionally filtered by a selector. * @param selector A string containing a selector expression to match elements against. @@ -1863,7 +1865,7 @@ $( "#stop" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ click(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "click" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1913,7 +1915,8 @@ $( "p" ).click(function() { $( "p" ).click(); ``` */ - click(handler?: JQuery.EventHandler | false): this; + click(handler?: JQuery.TypeEventHandler | + false): this; /** * Create a deep copy of the set of matched elements. * @param withDataAndEvents A Boolean indicating whether event handlers and data should be copied along with the elements. The @@ -2101,7 +2104,7 @@ $( "#frameDemo" ).contents().find( "a" ).css( "background-color", "#BADA55" ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ contextmenu(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "contextmenu" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -2155,7 +2158,8 @@ div.contextmenu(function() { ``` */ - contextmenu(handler?: JQuery.EventHandler | false): this; + contextmenu(handler?: JQuery.TypeEventHandler | + false): this; /** * Set one or more CSS properties for the set of matched elements. * @param propertyName A CSS property name. @@ -2616,7 +2620,7 @@ $( "button" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ dblclick(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "dblclick" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -2670,7 +2674,8 @@ divdbl.dblclick(function() { ``` */ - dblclick(handler?: JQuery.EventHandler | false): this; + dblclick(handler?: JQuery.TypeEventHandler | + false): this; /** * Set a timer to delay execution of subsequent items in the queue. * @param duration An integer indicating the number of milliseconds to delay execution of the next item in the queue. @@ -4293,7 +4298,7 @@ $( "p span" ).first().addClass( "highlight" ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focus(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "focus" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -4345,7 +4350,8 @@ $( document ).ready(function() { }); ``` */ - focus(handler?: JQuery.EventHandler | false): this; + focus(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "focusin" event. * @param eventData An object containing data that will be passed to the event handler. @@ -4359,7 +4365,7 @@ $( document ).ready(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focusin(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "focusin" event. * @param handler A function to execute each time the event is triggered. @@ -4399,7 +4405,8 @@ $( "p" ).focusin(function() { ``` */ - focusin(handler?: JQuery.EventHandler | false): this; + focusin(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "focusout" JavaScript event. * @param eventData An object containing data that will be passed to the event handler. @@ -4413,7 +4420,7 @@ $( "p" ).focusin(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focusout(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "focusout" JavaScript event. * @param handler A function to execute each time the event is triggered. @@ -4474,7 +4481,8 @@ $( "p" ) ``` */ - focusout(handler?: JQuery.EventHandler | false): this; + focusout(handler?: JQuery.TypeEventHandler | + false): this; /** * Retrieve one of the elements matched by the jQuery object. * @param index A zero-based integer indicating which element to retrieve. @@ -4917,12 +4925,11 @@ $( "button" ).click(function() { */ hide(duration_complete_options?: JQuery.Duration | ((this: TElement) => void) | JQuery.EffectsOptions): this; /** - * Bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements. - * @param handlerInOut A function to execute when the mouse pointer enters or leaves the element. + * Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements. + * @param handlerIn A function to execute when the mouse pointer enters the element. * @param handlerOut A function to execute when the mouse pointer leaves the element. * @see \`{@link https://api.jquery.com/hover/ }\` * @since 1.0 - * @since 1.4 * @deprecated ​ Deprecated. * * **Cause**: The `.hover()` method is a shorthand for the use of the `mouseover`/`mouseout` events. It is often a poor user interface choice because it does not allow for any small amounts of delay between when the mouse enters or exits an area and when the event fires. This can make it quite difficult to use with UI widgets such as drop-down menus. For more information on the problems of hovering, see the \`{@link http://cherne.net/brian/resources/jquery.hoverIntent.html hoverIntent plugin}\`. @@ -4990,6 +4997,21 @@ $( "td" ).hover( ```javascript $( "td" ).off( "mouseenter mouseleave" ); ``` + */ + hover(handlerIn: JQuery.TypeEventHandler | + false, + handlerOut: JQuery.TypeEventHandler | + false): this; + /** + * Bind a single handler to the matched elements, to be executed when the mouse pointer enters or leaves the elements. + * @param handlerInOut A function to execute when the mouse pointer enters or leaves the element. + * @see \`{@link https://api.jquery.com/hover/ }\` + * @since 1.4 + * @deprecated ​ Deprecated. + * + * **Cause**: The `.hover()` method is a shorthand for the use of the `mouseover`/`mouseout` events. It is often a poor user interface choice because it does not allow for any small amounts of delay between when the mouse enters or exits an area and when the event fires. This can make it quite difficult to use with UI widgets such as drop-down menus. For more information on the problems of hovering, see the \`{@link http://cherne.net/brian/resources/jquery.hoverIntent.html hoverIntent plugin}\`. + * + * **Solution**: Review uses of `.hover()` to determine if they are appropriate, and consider use of plugins such as `hoverIntent` as an alternative. The direct replacement for `.hover(fn1, fn2)`, is `.on("mouseenter", fn1).on("mouseleave", fn2)`. * @example ​ ````Slide the next sibling LI up or down on hover, and toggle a class. ```html @@ -5045,10 +5067,8 @@ $( "li" ) ``` */ - // HACK: The type parameter T is not used but ensures the 'event' callback parameter is typed correctly. - // tslint:disable-next-line:no-unnecessary-generics - hover(handlerInOut: JQuery.EventHandler | false, - handlerOut?: JQuery.EventHandler | false): this; + hover(handlerInOut: JQuery.TypeEventHandler | + false): this; /** * Set the HTML contents of each element in the set of matched elements. * @param htmlString_function _@param_ `htmlString_function` @@ -5862,7 +5882,7 @@ $( "li" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keydown(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -5934,7 +5954,8 @@ $( "#other" ).click(function() { ``` */ - keydown(handler?: JQuery.EventHandler | false): this; + keydown(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -5948,7 +5969,7 @@ $( "#other" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keypress(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6020,7 +6041,8 @@ $( "#other" ).click(function() { ``` */ - keypress(handler?: JQuery.EventHandler | false): this; + keypress(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6034,7 +6056,7 @@ $( "#other" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keyup(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6107,7 +6129,8 @@ $( "#other").click(function() { ``` */ - keyup(handler?: JQuery.EventHandler | false): this; + keyup(handler?: JQuery.TypeEventHandler | + false): this; /** * Reduce the set of matched elements to the final one in the set. * @see \`{@link https://api.jquery.com/last/ }\` @@ -6396,7 +6419,7 @@ $( "input" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mousedown(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6434,7 +6457,8 @@ $( "p" ) ``` */ - mousedown(handler?: JQuery.EventHandler | false): this; + mousedown(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6448,7 +6472,7 @@ $( "p" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseenter(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. * @param handler A function to execute each time the event is triggered. @@ -6529,7 +6553,8 @@ $( "div.enterleave" ) ``` */ - mouseenter(handler?: JQuery.EventHandler | false): this; + mouseenter(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6543,7 +6568,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseleave(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. * @param handler A function to execute each time the event is triggered. @@ -6622,7 +6647,8 @@ $( "div.enterleave" ) ``` */ - mouseleave(handler?: JQuery.EventHandler | false): this; + mouseleave(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6636,7 +6662,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mousemove(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6700,7 +6726,8 @@ $( "div" ).mousemove(function( event ) { ``` */ - mousemove(handler?: JQuery.EventHandler | false): this; + mousemove(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6714,7 +6741,7 @@ $( "div" ).mousemove(function( event ) { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseout(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6795,7 +6822,8 @@ $( "div.enterleave" ) ``` */ - mouseout(handler?: JQuery.EventHandler | false): this; + mouseout(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6809,7 +6837,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseover(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6890,7 +6918,8 @@ $( "div.enterleave" ) ``` */ - mouseover(handler?: JQuery.EventHandler | false): this; + mouseover(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -6904,7 +6933,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseup(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6942,7 +6971,8 @@ $( "p" ) ``` */ - mouseup(handler?: JQuery.EventHandler | false): this; + mouseup(handler?: JQuery.TypeEventHandler | + false): this; /** * Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector. * @param selector A string containing a selector expression to match elements against. @@ -9970,7 +10000,7 @@ $( "button" ).on( "click", function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ resize(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -9988,7 +10018,8 @@ $( window ).resize(function() { }); ``` */ - resize(handler?: JQuery.EventHandler | false): this; + resize(handler?: JQuery.TypeEventHandler | + false): this; /** * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -10002,7 +10033,7 @@ $( window ).resize(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ scroll(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -10052,7 +10083,8 @@ $( window ).scroll(function() { ``` */ - scroll(handler?: JQuery.EventHandler | false): this; + scroll(handler?: JQuery.TypeEventHandler | + false): this; /** * Set the current horizontal position of the scroll bar for each of the set of matched elements. * @param value An integer indicating the new position to set the scroll bar to. @@ -10226,7 +10258,7 @@ $( "p:last" ).text( "scrollTop:" + p.scrollTop() ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ select(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "select" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -10275,7 +10307,8 @@ $( ":input" ).select(function() { $( "input" ).select(); ``` */ - select(handler?: JQuery.EventHandler | false): this; + select(handler?: JQuery.TypeEventHandler | + false): this; /** * Encode a set of form elements as a string for submission. * @see \`{@link https://api.jquery.com/serialize/ }\` @@ -11246,7 +11279,7 @@ $( "#toggle" ).on( "click", function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ submit(eventData: TData, - handler: JQuery.EventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "submit" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -11315,7 +11348,8 @@ $( "form" ).submit(function() { $( "form:first" ).submit(); ``` */ - submit(handler?: JQuery.EventHandler | false): this; + submit(handler?: JQuery.TypeEventHandler | + false): this; /** * Set the content of each element in the set of matched elements to the specified text. * @param text_function _@param_ `text_function` diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index b08b48d0b0..069e8613d6 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -3916,6 +3916,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }); } @@ -3948,6 +3954,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType any + this; + // $ExpectType ClickEvent + event; } }); } @@ -4139,6 +4151,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType any + this; + // $ExpectType ClickEvent + event; } }, 'td', 'myData'); @@ -4150,6 +4168,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }, null, 'myData'); @@ -4161,6 +4185,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }, undefined, 'myData'); @@ -4172,6 +4202,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType any + this; + // $ExpectType ClickEvent + event; } }, 'td'); @@ -4183,6 +4219,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }, 3); @@ -4194,6 +4236,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }); } @@ -4261,6 +4309,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType any + this; + // $ExpectType ClickEvent + event; } }, 'td', 'myData'); @@ -4272,6 +4326,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }, null, 'myData'); @@ -4283,6 +4343,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }, undefined, 'myData'); @@ -4294,6 +4360,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType any + this; + // $ExpectType ClickEvent + event; } }, 'td'); @@ -4305,6 +4377,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }, 3); @@ -4316,6 +4394,12 @@ function JQuery() { this; // $ExpectType TriggeredEvent event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; } }); } @@ -4445,7 +4529,7 @@ function JQuery() { $('p').blur('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType BlurEvent event; }); @@ -4453,7 +4537,7 @@ function JQuery() { $('p').blur(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType BlurEvent event; }); @@ -4469,7 +4553,7 @@ function JQuery() { $('p').change('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ChangeEvent event; }); @@ -4477,7 +4561,7 @@ function JQuery() { $('p').change(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ChangeEvent event; }); @@ -4493,7 +4577,7 @@ function JQuery() { $('p').click('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ClickEvent event; }); @@ -4501,7 +4585,7 @@ function JQuery() { $('p').click(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ClickEvent event; }); @@ -4517,7 +4601,7 @@ function JQuery() { $('p').contextmenu('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ContextMenuEvent event; }); @@ -4525,7 +4609,7 @@ function JQuery() { $('p').contextmenu(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ContextMenuEvent event; }); @@ -4541,7 +4625,7 @@ function JQuery() { $('p').dblclick('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType DoubleClickEvent event; }); @@ -4549,7 +4633,7 @@ function JQuery() { $('p').dblclick(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType DoubleClickEvent event; }); @@ -4565,7 +4649,7 @@ function JQuery() { $('p').focus('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType FocusEvent event; }); @@ -4573,7 +4657,7 @@ function JQuery() { $('p').focus(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType FocusEvent event; }); @@ -4589,7 +4673,7 @@ function JQuery() { $('p').focusin('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType FocusInEvent event; }); @@ -4597,7 +4681,7 @@ function JQuery() { $('p').focusin(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType FocusInEvent event; }); @@ -4613,7 +4697,7 @@ function JQuery() { $('p').focusout('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType FocusOutEvent event; }); @@ -4621,7 +4705,7 @@ function JQuery() { $('p').focusout(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType FocusOutEvent event; }); @@ -4637,7 +4721,7 @@ function JQuery() { $('p').keydown('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType KeyDownEvent event; }); @@ -4645,7 +4729,7 @@ function JQuery() { $('p').keydown(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType KeyDownEvent event; }); @@ -4661,7 +4745,7 @@ function JQuery() { $('p').keypress('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType KeyPressEvent event; }); @@ -4669,7 +4753,7 @@ function JQuery() { $('p').keypress(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType KeyPressEvent event; }); @@ -4685,7 +4769,7 @@ function JQuery() { $('p').keyup('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType KeyUpEvent event; }); @@ -4693,7 +4777,7 @@ function JQuery() { $('p').keyup(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType KeyUpEvent event; }); @@ -4709,7 +4793,7 @@ function JQuery() { $('p').mousedown('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseDownEvent event; }); @@ -4717,7 +4801,7 @@ function JQuery() { $('p').mousedown(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseDownEvent event; }); @@ -4733,7 +4817,7 @@ function JQuery() { $('p').mouseenter('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseEnterEvent event; }); @@ -4741,7 +4825,7 @@ function JQuery() { $('p').mouseenter(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseEnterEvent event; }); @@ -4757,7 +4841,7 @@ function JQuery() { $('p').mouseleave('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseLeaveEvent event; }); @@ -4765,7 +4849,7 @@ function JQuery() { $('p').mouseleave(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseLeaveEvent event; }); @@ -4781,7 +4865,7 @@ function JQuery() { $('p').mousemove('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseMoveEvent event; }); @@ -4789,7 +4873,7 @@ function JQuery() { $('p').mousemove(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseMoveEvent event; }); @@ -4805,7 +4889,7 @@ function JQuery() { $('p').mouseout('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseOutEvent event; }); @@ -4813,7 +4897,7 @@ function JQuery() { $('p').mouseout(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseOutEvent event; }); @@ -4829,7 +4913,7 @@ function JQuery() { $('p').mouseover('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseOverEvent event; }); @@ -4837,7 +4921,7 @@ function JQuery() { $('p').mouseover(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseOverEvent event; }); @@ -4853,7 +4937,7 @@ function JQuery() { $('p').mouseup('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseUpEvent event; }); @@ -4861,7 +4945,7 @@ function JQuery() { $('p').mouseup(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseUpEvent event; }); @@ -4877,7 +4961,7 @@ function JQuery() { $('p').resize('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ResizeEvent event; }); @@ -4885,7 +4969,7 @@ function JQuery() { $('p').resize(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ResizeEvent event; }); @@ -4901,7 +4985,7 @@ function JQuery() { $('p').scroll('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ScrollEvent event; }); @@ -4909,7 +4993,7 @@ function JQuery() { $('p').scroll(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType ScrollEvent event; }); @@ -4925,7 +5009,7 @@ function JQuery() { $('p').select('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType SelectEvent event; }); @@ -4933,7 +5017,7 @@ function JQuery() { $('p').select(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType SelectEvent event; }); @@ -4949,7 +5033,7 @@ function JQuery() { $('p').submit('myData', function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType SubmitEvent event; }); @@ -4957,7 +5041,7 @@ function JQuery() { $('p').submit(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType SubmitEvent event; }); @@ -4973,12 +5057,12 @@ function JQuery() { $('p').hover(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseEnterEvent event; }, function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseLeaveEvent event; }); @@ -4986,7 +5070,7 @@ function JQuery() { $('p').hover(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseEnterEvent event; }, false); @@ -4994,7 +5078,7 @@ function JQuery() { $('p').hover(false, function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseLeaveEvent event; }); @@ -5005,8 +5089,23 @@ function JQuery() { $('p').hover(function(event) { // $ExpectType HTMLElement this; - // $ExpectType Event + // $ExpectType MouseEnterEvent | MouseLeaveEvent event; + + switch (event.type) { + case 'mouseover': + // $ExpectType MouseEnterEvent + event; + break; + case 'mouseout': + // $ExpectType MouseLeaveEvent + event; + break; + default: + // $ExpectType never + event; + break; + } }); // $ExpectType JQuery diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index d966f1b787..24979fb620 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -4744,12 +4744,1290 @@ $( "button" ).click(function( event ) { result?: any; } + // region Event + // #region Event + + interface EventBase< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends TriggeredEvent { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. +```javascript +$( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" +}); +``` + */ + relatedTarget?: undefined; + + // Event + + bubbles: boolean; + cancelable: boolean; + eventPhase: number; + + // UIEvent + + detail: undefined; + view: undefined; + + // MouseEvent + + button: undefined; + buttons: undefined; + clientX: undefined; + clientY: undefined; + offsetX: undefined; + offsetY: undefined; + /** + * The mouse position relative to the left edge of the document. + * @see \`{@link https://api.jquery.com/event.pageX/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageX demo + + + + +​ +
+​ + +​ + + +``` + */ + pageX: undefined; + /** + * The mouse position relative to the top edge of the document. + * @see \`{@link https://api.jquery.com/event.pageY/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageY demo + + + + +​ +
+​ + +​ + + +``` + */ + pageY: undefined; + screenX: undefined; + screenY: undefined; + /** @deprecated */ + toElement: undefined; + + // PointerEvent + + pointerId: undefined; + pointerType: undefined; + + // KeyboardEvent + + /** @deprecated */ + char: undefined; + /** @deprecated */ + charCode: undefined; + key: undefined; + /** @deprecated */ + keyCode: undefined; + + // TouchEvent + + changedTouches: undefined; + targetTouches: undefined; + touches: undefined; + + // MouseEvent, KeyboardEvent + + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see \`{@link https://api.jquery.com/event.which/ }\` + * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. + * @example ​ ````Log which key was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + * @example ​ ````Log which mouse button was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + */ + which: undefined; + + // MouseEvent, KeyboardEvent, TouchEvent + + altKey: undefined; + ctrlKey: undefined; + /** + * Indicates whether the META key was pressed when the event fired. + * @see \`{@link https://api.jquery.com/event.metaKey/ }\` + * @since 1.0.4 + * @example ​ ````Determine whether the META key was pressed when the event fired. +```html + + + + + event.metaKey demo + + + + +​ + +
+​ + +​ + + +``` + */ + metaKey: undefined; + shiftKey: undefined; + + originalEvent?: _Event; + } + + interface ChangeEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends EventBase { + type: 'change'; + } + + interface ResizeEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends EventBase { + type: 'resize'; + } + + interface ScrollEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends EventBase { + type: 'scroll'; + } + + interface SelectEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends EventBase { + type: 'select'; + } + + interface SubmitEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends EventBase { + type: 'submit'; + } + + // #endregion + + // region UIEvent + // #region UIEvent + + interface UIEventBase< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends TriggeredEvent { + // Event + + bubbles: boolean; + cancelable: boolean; + eventPhase: number; + + // UIEvent + + detail: number; + view: Window; + + originalEvent?: _UIEvent; + } + + // region MouseEvent + // #region MouseEvent + + interface MouseEventBase< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends UIEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. +```javascript +$( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" +}); +``` + */ + relatedTarget?: EventTarget | null; + + // MouseEvent + + button: number; + buttons: number; + clientX: number; + clientY: number; + offsetX: number; + offsetY: number; + /** + * The mouse position relative to the left edge of the document. + * @see \`{@link https://api.jquery.com/event.pageX/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageX demo + + + + +​ +
+​ + +​ + + +``` + */ + pageX: number; + /** + * The mouse position relative to the top edge of the document. + * @see \`{@link https://api.jquery.com/event.pageY/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageY demo + + + + +​ +
+​ + +​ + + +``` + */ + pageY: number; + screenX: number; + screenY: number; + /** @deprecated */ + toElement: Element; + + // PointerEvent + + pointerId: undefined; + pointerType: undefined; + + // KeyboardEvent + + /** @deprecated */ + char: undefined; + /** @deprecated */ + charCode: undefined; + key: undefined; + /** @deprecated */ + keyCode: undefined; + + // TouchEvent + + changedTouches: undefined; + targetTouches: undefined; + touches: undefined; + + // MouseEvent, KeyboardEvent + + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see \`{@link https://api.jquery.com/event.which/ }\` + * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. + * @example ​ ````Log which key was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + * @example ​ ````Log which mouse button was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + */ + which: number; + + // MouseEvent, KeyboardEvent, TouchEvent + + altKey: boolean; + ctrlKey: boolean; + /** + * Indicates whether the META key was pressed when the event fired. + * @see \`{@link https://api.jquery.com/event.metaKey/ }\` + * @since 1.0.4 + * @example ​ ````Determine whether the META key was pressed when the event fired. +```html + + + + + event.metaKey demo + + + + +​ + +
+​ + +​ + + +``` + */ + metaKey: boolean; + shiftKey: boolean; + + originalEvent?: _MouseEvent; + } + + interface ClickEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. + ```javascript + $( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" + }); + ``` + */ + relatedTarget?: null; + + type: 'click'; + } + + interface ContextMenuEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. + ```javascript + $( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" + }); + ``` + */ + relatedTarget?: null; + + type: 'contextmenu'; + } + + interface DoubleClickEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. + ```javascript + $( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" + }); + ``` + */ + relatedTarget?: null; + + type: 'dblclick'; + } + + interface MouseDownEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. + ```javascript + $( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" + }); + ``` + */ + relatedTarget?: null; + + type: 'mousedown'; + } + + interface MouseEnterEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + // Special handling by jQuery. + type: 'mouseover'; + } + + interface MouseLeaveEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + // Special handling by jQuery. + type: 'mouseout'; + } + + interface MouseMoveEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. + ```javascript + $( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" + }); + ``` + */ + relatedTarget?: null; + + type: 'mousemove'; + } + + interface MouseOutEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + type: 'mouseout'; + } + + interface MouseOverEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + type: 'mouseover'; + } + + interface MouseUpEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends MouseEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. + ```javascript + $( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" + }); + ``` + */ + relatedTarget?: null; + + type: 'mouseup'; + } + + // #endregion + + // region KeyboardEvent + // #region KeyboardEvent + + interface KeyboardEventBase< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends UIEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. +```javascript +$( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" +}); +``` + */ + relatedTarget?: undefined; + + // MouseEvent + + button: undefined; + buttons: undefined; + clientX: undefined; + clientY: undefined; + offsetX: undefined; + offsetY: undefined; + /** + * The mouse position relative to the left edge of the document. + * @see \`{@link https://api.jquery.com/event.pageX/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageX demo + + + + +​ +
+​ + +​ + + +``` + */ + pageX: undefined; + /** + * The mouse position relative to the top edge of the document. + * @see \`{@link https://api.jquery.com/event.pageY/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageY demo + + + + +​ +
+​ + +​ + + +``` + */ + pageY: undefined; + screenX: undefined; + screenY: undefined; + /** @deprecated */ + toElement: undefined; + + // PointerEvent + + pointerId: undefined; + pointerType: undefined; + + // KeyboardEvent + + /** @deprecated */ + char: string | undefined; + /** @deprecated */ + charCode: number; + key: string; + /** @deprecated */ + keyCode: number; + + // TouchEvent + + changedTouches: undefined; + targetTouches: undefined; + touches: undefined; + + // MouseEvent, KeyboardEvent + + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see \`{@link https://api.jquery.com/event.which/ }\` + * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. + * @example ​ ````Log which key was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + * @example ​ ````Log which mouse button was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + */ + which: number; + + // MouseEvent, KeyboardEvent, TouchEvent + + altKey: boolean; + ctrlKey: boolean; + /** + * Indicates whether the META key was pressed when the event fired. + * @see \`{@link https://api.jquery.com/event.metaKey/ }\` + * @since 1.0.4 + * @example ​ ````Determine whether the META key was pressed when the event fired. +```html + + + + + event.metaKey demo + + + + +​ + +
+​ + +​ + + +``` + */ + metaKey: boolean; + shiftKey: boolean; + + originalEvent?: _KeyboardEvent; + } + + interface KeyDownEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends KeyboardEventBase { + type: 'keydown'; + } + + interface KeyPressEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends KeyboardEventBase { + type: 'keypress'; + } + + interface KeyUpEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends KeyboardEventBase { + type: 'keyup'; + } + + // #endregion + + // region FocusEvent + // #region FocusEvent + + interface FocusEventBase< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends UIEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. +```javascript +$( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" +}); +``` + */ + relatedTarget?: EventTarget | null; + + // MouseEvent + + button: undefined; + buttons: undefined; + clientX: undefined; + clientY: undefined; + offsetX: undefined; + offsetY: undefined; + /** + * The mouse position relative to the left edge of the document. + * @see \`{@link https://api.jquery.com/event.pageX/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageX demo + + + + +​ +
+​ + +​ + + +``` + */ + pageX: undefined; + /** + * The mouse position relative to the top edge of the document. + * @see \`{@link https://api.jquery.com/event.pageY/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageY demo + + + + +​ +
+​ + +​ + + +``` + */ + pageY: undefined; + screenX: undefined; + screenY: undefined; + /** @deprecated */ + toElement: undefined; + + // PointerEvent + + pointerId: undefined; + pointerType: undefined; + + // KeyboardEvent + + /** @deprecated */ + char: undefined; + /** @deprecated */ + charCode: undefined; + key: undefined; + /** @deprecated */ + keyCode: undefined; + + // TouchEvent + + changedTouches: undefined; + targetTouches: undefined; + touches: undefined; + + // MouseEvent, KeyboardEvent + + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see \`{@link https://api.jquery.com/event.which/ }\` + * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. + * @example ​ ````Log which key was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + * @example ​ ````Log which mouse button was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + */ + which: undefined; + + // MouseEvent, KeyboardEvent, TouchEvent + + altKey: undefined; + ctrlKey: undefined; + /** + * Indicates whether the META key was pressed when the event fired. + * @see \`{@link https://api.jquery.com/event.metaKey/ }\` + * @since 1.0.4 + * @example ​ ````Determine whether the META key was pressed when the event fired. +```html + + + + + event.metaKey demo + + + + +​ + +
+​ + +​ + + +``` + */ + metaKey: undefined; + shiftKey: undefined; + + originalEvent?: _FocusEvent; + } + + interface BlurEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends FocusEventBase { + type: 'blur'; + } + + interface FocusEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends FocusEventBase { + type: 'focus'; + } + + interface FocusInEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends FocusEventBase { + type: 'focusin'; + } + + interface FocusOutEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any, + TTarget = any + > extends FocusEventBase { + type: 'focusout'; + } + + // #endregion + + // #endregion + interface TypeToTriggeredEventMap< TDelegateTarget, TData, TCurrentTarget, TTarget > { + // Event + + change: ChangeEvent; + resize: ResizeEvent; + scroll: ScrollEvent; + select: SelectEvent; + submit: SubmitEvent; + + // UIEvent + + // MouseEvent + + click: ClickEvent; + contextmenu: ContextMenuEvent; + dblclick: DoubleClickEvent; + mousedown: MouseDownEvent; + mouseenter: MouseEnterEvent; + mouseleave: MouseLeaveEvent; + mousemove: MouseMoveEvent; + mouseout: MouseOutEvent; + mouseover: MouseOverEvent; + mouseup: MouseUpEvent; + + // KeyboardEvent + + keydown: KeyDownEvent; + keypress: KeyPressEvent; + keyup: KeyUpEvent; + + // FocusEvent + + blur: BlurEvent; + focus: FocusEvent; + focusin: FocusInEvent; + focusout: FocusOutEvent; + [type: string]: TriggeredEvent; } @@ -4985,6 +6263,10 @@ declare const jQuery: JQueryStatic; declare const $: JQueryStatic; type _Event = Event; +type _UIEvent = UIEvent; +type _MouseEvent = MouseEvent; +type _KeyboardEvent = KeyboardEvent; +type _FocusEvent = FocusEvent; // region ES5 compatibility // #region ES5 compatibility From acc34c5a2347ae1d58bda9dd72fe22c9f56ad959 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 10:50:28 -0400 Subject: [PATCH 080/792] [angular] Update merging tests for jQuery Events API changes. --- types/angular/test/jquery3-merging-tests.ts | 210 +------------------- 1 file changed, 10 insertions(+), 200 deletions(-) diff --git a/types/angular/test/jquery3-merging-tests.ts b/types/angular/test/jquery3-merging-tests.ts index 507c58b67e..da61a6f0bc 100644 --- a/types/angular/test/jquery3-merging-tests.ts +++ b/types/angular/test/jquery3-merging-tests.ts @@ -94,8 +94,6 @@ function JQuery() { } function bind() { - interface I1 { kind: 'I1'; } - // $ExpectType JQuery $('p').bind('myEvent', 'myData', function(event) { // TODO: $ExpectType HTMLElement @@ -104,14 +102,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').bind('myEvent', 'myData', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').bind('myEvent', function(event) { // TODO: $ExpectType HTMLElement @@ -120,14 +110,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('p').bind('myEvent', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('p').bind('myEvent', false); @@ -139,12 +121,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }); @@ -164,27 +140,15 @@ function JQuery() { } function off() { - function defaultContext_defaultData(this: HTMLElement, event: JQueryEventObject) { } + function defaultData(this: HTMLElement, event: JQueryEventObject) { } - function defaultContext_customData(this: HTMLElement, event: JQueryEventObject) { } - - function customContext_defaultData(this: I1, event: JQueryEventObject) { } - - function customContext_customData(this: I1, event: JQueryEventObject) { } - - interface I1 { kind: 'I1'; } + function customData(this: HTMLElement, event: JQueryEventObject) { } // $ExpectType JQuery - $('table').off('myEvent', 'td', defaultContext_defaultData); + $('table').off('myEvent', 'td', defaultData); // $ExpectType JQuery - $('table').off('myEvent', 'td', defaultContext_customData); - - // $ExpectType JQuery - $('table').off('myEvent', 'td', customContext_defaultData); - - // $ExpectType JQuery - $('table').off('myEvent', 'td', customContext_customData); + $('table').off('myEvent', 'td', customData); // $ExpectType JQuery $('table').off('myEvent', 'td', false); @@ -193,16 +157,10 @@ function JQuery() { $('table').off('myEvent', 'td'); // $ExpectType JQuery - $('table').off('myEvent', defaultContext_defaultData); + $('table').off('myEvent', defaultData); // $ExpectType JQuery - $('table').off('myEvent', defaultContext_customData); - - // $ExpectType JQuery - $('table').off('myEvent', customContext_defaultData); - - // $ExpectType JQuery - $('table').off('myEvent', customContext_customData); + $('table').off('myEvent', customData); // $ExpectType JQuery $('table').off('myEvent', false); @@ -213,19 +171,15 @@ function JQuery() { // $ExpectType JQuery $('table').off({ myEvent1: false, - defaultContext_defaultData, - defaultContext_customData, - customContext_defaultData, - customContext_customData + defaultData, + customData }, 'td'); // $ExpectType JQuery $('table').off({ myEvent1: false, - defaultContext_defaultData, - defaultContext_customData, - customContext_defaultData, - customContext_customData + defaultData, + customData }); // $ExpectType JQuery @@ -236,8 +190,6 @@ function JQuery() { } function on() { - interface I1 { kind: 'I1'; } - // $ExpectType JQuery $('table').on('myEvent', 'td', 'myData', function(event) { // TODO: $ExpectType HTMLElement @@ -246,14 +198,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', 'td', 'myData', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', null, 'myData', function(event) { // TODO: $ExpectType HTMLElement @@ -262,14 +206,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', null, 'myData', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', 'td', function(event) { // TODO: $ExpectType HTMLElement @@ -278,14 +214,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', 'td', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', 'td', false); @@ -297,14 +225,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', 3, function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', function(event) { // TODO: $ExpectType HTMLElement @@ -313,14 +233,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').on('myEvent', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').on('myEvent', false); @@ -332,12 +244,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, 'td', 'myData'); @@ -349,12 +255,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, null, 'myData'); @@ -366,12 +266,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, 'td'); @@ -383,12 +277,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, 3); @@ -400,19 +288,11 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }); } function one() { - interface I1 { kind: 'I1'; } - // $ExpectType JQuery $('table').one('myEvent', 'td', 'myData', function(event) { // TODO: $ExpectType HTMLElement @@ -421,14 +301,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', 'td', 'myData', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', null, 'myData', function(event) { // TODO: $ExpectType HTMLElement @@ -437,14 +309,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', null, 'myData', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', 'td', function(event) { // TODO: $ExpectType HTMLElement @@ -453,14 +317,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', 'td', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', 'td', false); @@ -472,14 +328,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', 3, function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', function(event) { // TODO: $ExpectType HTMLElement @@ -488,14 +336,6 @@ function JQuery() { event; }); - // $ExpectType JQuery - $('table').one('myEvent', function(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; - }); - // $ExpectType JQuery $('table').one('myEvent', false); @@ -507,12 +347,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, 'td', 'myData'); @@ -524,12 +358,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, null, 'myData'); @@ -541,12 +369,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, 'td'); @@ -558,12 +380,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }, 3); @@ -575,12 +391,6 @@ function JQuery() { this; // TODO: $ExpectType Event event; - }, - myEvent3(this: I1, event) { - // $ExpectType I1 - this; - // TODO: $ExpectType Event - event; } }); } From 68c38a850c846788505bc8fd34398e19136983e0 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:45:11 -0400 Subject: [PATCH 081/792] [backbone] Fix test failure in `backbone.marionette` due to changes in jQuery Events API. --- types/backbone/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/backbone/index.d.ts b/types/backbone/index.d.ts index ca36541735..a881284c8f 100644 --- a/types/backbone/index.d.ts +++ b/types/backbone/index.d.ts @@ -92,7 +92,7 @@ declare namespace Backbone { } interface EventsHash { - [selector: string]: string | {(eventObject: JQueryEventObject): void}; + [selector: string]: string | {(eventObject: JQuery.TriggeredEvent): void}; } export const Events: Events; From b6bb6a64fd214d0f25711c6e79572cf35ad1f07c Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:01:29 -0400 Subject: [PATCH 082/792] [bootstrap] Update API for jQuery Events API changes. --- types/bootstrap/index.d.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/types/bootstrap/index.d.ts b/types/bootstrap/index.d.ts index 8a815bccd5..9744731237 100755 --- a/types/bootstrap/index.d.ts +++ b/types/bootstrap/index.d.ts @@ -322,7 +322,7 @@ export interface TooltipOption { // Events // -------------------------------------------------------------------------------------- -export interface CarouselEventHandler extends JQuery.Event { +export interface CarouselEventHandler extends JQuery.TriggeredEvent { /** * The direction in which the carousel is sliding. */ @@ -339,6 +339,10 @@ export interface CarouselEventHandler extends JQuery.Event extends JQuery.TriggeredEvent { + relatedTarget: HTMLElement; +} + export type AlertEvent = "close.bs.alert" | "closed.bs.alert"; export type CarouselEvent = "slide.bs.carousel" | "slid.bs.carousel"; export type CollapseEvent = "show.bs.collapse" | "shown.bs.collapse" | "hide.bs.collapse" | "hidden.bs.collapse"; @@ -383,9 +387,10 @@ declare global { tooltip(options?: TooltipOption): this; on(events: CarouselEvent, handler: JQuery.EventHandlerBase>): this; + on(events: TapEvent, handler: JQuery.EventHandlerBase>): this; on(events: AlertEvent | CollapseEvent | DropdownEvent | ModalEvent | - PopoverEvent | ScrollspyEvent | TapEvent | TooltipEvent, + PopoverEvent | ScrollspyEvent | TooltipEvent, handler: JQuery.EventHandler): this; } } From 5f6b28023b302f089330ef5bb86ac8d805df5b75 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:03:13 -0400 Subject: [PATCH 083/792] [bootstrap-slider] Fix test failure due to jQuery Events API changes. --- types/bootstrap-slider/bootstrap-slider-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/bootstrap-slider/bootstrap-slider-tests.ts b/types/bootstrap-slider/bootstrap-slider-tests.ts index 9b2a1a2014..d3ffdeedeb 100644 --- a/types/bootstrap-slider/bootstrap-slider-tests.ts +++ b/types/bootstrap-slider/bootstrap-slider-tests.ts @@ -42,7 +42,7 @@ $(() => { $('#ex7').slider(); - $('#ex7-enabled').click(function(this: HTMLInputElement) { + $('#ex7-enabled').click(function() { if (this.checked) { // With JQuery $('#ex7').slider('enable'); From c1ce5ef2c241a4fdcfc4b181428a1f6500dcaa0d Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:04:44 -0400 Subject: [PATCH 084/792] [jquery-focus-exit] Update API for jQuery Events API changes. --- types/jquery-focus-exit/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/jquery-focus-exit/index.d.ts b/types/jquery-focus-exit/index.d.ts index 8787136a4e..d4da0a1f18 100644 --- a/types/jquery-focus-exit/index.d.ts +++ b/types/jquery-focus-exit/index.d.ts @@ -14,7 +14,7 @@ export interface FocusElements { declare global { interface JQuery { focusExit(options?: { debug: boolean }): JQuery; - on(event: 'focusExit', handler: ((event: JQuery.Event, data: FocusElements) => void)): JQuery; - one(event: 'focusin', handler: ((event: JQuery.Event) => void)): JQuery; + on(event: 'focusExit', handler: ((event: JQuery.TriggeredEvent, data: FocusElements) => void)): JQuery; + one(event: 'focusin', handler: ((event: JQuery.TriggeredEvent) => void)): JQuery; } } From 8914a468a462141bd3817bbbccaa2f0ecb947436 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:05:22 -0400 Subject: [PATCH 085/792] [jquery-mouse-exit] Update API for jQuery Events API changes. --- types/jquery-mouse-exit/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jquery-mouse-exit/index.d.ts b/types/jquery-mouse-exit/index.d.ts index f0ba17996e..651a7b3f85 100644 --- a/types/jquery-mouse-exit/index.d.ts +++ b/types/jquery-mouse-exit/index.d.ts @@ -18,6 +18,6 @@ export type FocusElements = Partial<{ declare global { interface JQuery { mouseExit(options?: Options): JQuery; - on(event: 'mouseExit', handler: ((event: JQuery.Event, data: FocusElements) => void)): JQuery; + on(event: 'mouseExit', handler: ((event: JQuery.TriggeredEvent, data: FocusElements) => void)): JQuery; } } From e1d3c4aba92261ee7d9090f713524243fa5433b6 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:07:58 -0400 Subject: [PATCH 086/792] [semantic-ui-form] Update API for jQuery Events API changes. --- types/semantic-ui-form/global.d.ts | 2 +- types/semantic-ui-form/semantic-ui-form-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/semantic-ui-form/global.d.ts b/types/semantic-ui-form/global.d.ts index 8e5b2c20b8..1f3294c8d6 100644 --- a/types/semantic-ui-form/global.d.ts +++ b/types/semantic-ui-form/global.d.ts @@ -212,7 +212,7 @@ declare namespace SemanticUI { /** * Callback if a form is all valid */ - onSuccess(this: JQuery, event: JQuery.Event, fields: any): void; + onSuccess(this: JQuery, event: JQuery.TriggeredEvent, fields: any): void; /** * Callback if any form field is invalid */ diff --git a/types/semantic-ui-form/semantic-ui-form-tests.ts b/types/semantic-ui-form/semantic-ui-form-tests.ts index f17ca33112..d481cb00ad 100644 --- a/types/semantic-ui-form/semantic-ui-form-tests.ts +++ b/types/semantic-ui-form/semantic-ui-form-tests.ts @@ -144,7 +144,7 @@ function test_form() { }, onSuccess(event, fields) { this; // $ExpectType JQuery - event; // $ExpectType Event + event; // $ExpectType TriggeredEvent fields; // $ExpectType any }, onFailure(formErrors, fields) { From 8f46997efa62f7e42f8c87a3efde06e7ec69ec7e Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:28:43 -0400 Subject: [PATCH 087/792] [sharepoint] Fix test failure due to jQuery Events API changes. --- types/sharepoint/sharepoint-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/sharepoint/sharepoint-tests.ts b/types/sharepoint/sharepoint-tests.ts index e76536cd18..d3bbe1f808 100644 --- a/types/sharepoint/sharepoint-tests.ts +++ b/types/sharepoint/sharepoint-tests.ts @@ -2038,7 +2038,7 @@ namespace _ { // do is retrieve a reference to the term set with the same ID as the div, and // then add the term that belong to that term set under the div that was clicked. - function showTerms(event: JQuery.Event, groupID: SP.Guid, termSetID: SP.Guid) { + function showTerms(event: JQuery.ClickEvent, groupID: SP.Guid, termSetID: SP.Guid) { // First, cancel the bubble so that the group div click handler does not also fire // because that removes all term set divs and we don't want that here. event.originalEvent.cancelBubble = true; From 3a54bad0684cc88f91cfeac115d57554fc494c62 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 28 Oct 2018 11:26:51 -0400 Subject: [PATCH 088/792] [jquery] Add support for touch events. Fixes test failures in `viewporter` due to changes in jQuery Events API. --- types/jquery/misc.d.ts | 271 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index 24979fb620..dd05435043 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -5716,6 +5716,269 @@ $( "#checkMetaKey" ).click(function( event ) { // #endregion + // region TouchEvent + // #region TouchEvent + + interface TouchEventBase< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any + > extends UIEventBase { + /** + * The other DOM element involved in the event, if any. + * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` + * @since 1.1.4 + * @example ​ ````On mouseout of anchors, alert the element type being entered. +```javascript +$( "a" ).mouseout(function( event ) { + alert( event.relatedTarget.nodeName ); // "DIV" +}); +``` + */ + relatedTarget?: undefined; + + // MouseEvent + + button: undefined; + buttons: undefined; + clientX: undefined; + clientY: undefined; + offsetX: undefined; + offsetY: undefined; + /** + * The mouse position relative to the left edge of the document. + * @see \`{@link https://api.jquery.com/event.pageX/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageX demo + + + + +​ +
+​ + +​ + + +``` + */ + pageX: undefined; + /** + * The mouse position relative to the top edge of the document. + * @see \`{@link https://api.jquery.com/event.pageY/ }\` + * @since 1.0.4 + * @example ​ ````Show the mouse position relative to the left and top edges of the document (within this iframe). +```html + + + + + event.pageY demo + + + + +​ +
+​ + +​ + + +``` + */ + pageY: undefined; + screenX: undefined; + screenY: undefined; + /** @deprecated */ + toElement: undefined; + + // PointerEvent + + pointerId: undefined; + pointerType: undefined; + + // KeyboardEvent + + /** @deprecated */ + char: undefined; + /** @deprecated */ + charCode: undefined; + key: undefined; + /** @deprecated */ + keyCode: undefined; + + // TouchEvent + + changedTouches: TouchList; + targetTouches: TouchList; + touches: TouchList; + + // MouseEvent, KeyboardEvent + + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see \`{@link https://api.jquery.com/event.which/ }\` + * @since 1.1.3 + * @deprecated ​ Deprecated since 3.3. See \`{@link https://github.com/jquery/api.jquery.com/issues/821 }\`. + * @example ​ ````Log which key was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + * @example ​ ````Log which mouse button was depressed. +```html + + + + + event.which demo + + + +​ + +
+​ + +​ + + +``` + */ + which: undefined; + + // MouseEvent, KeyboardEvent, TouchEvent + + altKey: boolean; + ctrlKey: boolean; + /** + * Indicates whether the META key was pressed when the event fired. + * @see \`{@link https://api.jquery.com/event.metaKey/ }\` + * @since 1.0.4 + * @example ​ ````Determine whether the META key was pressed when the event fired. +```html + + + + + event.metaKey demo + + + + +​ + +
+​ + +​ + + +``` + */ + metaKey: boolean; + shiftKey: boolean; + + originalEvent?: _TouchEvent; + } + + interface TouchCancelEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any + > extends TouchEventBase { + type: 'touchcancel'; + } + + interface TouchEndEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any + > extends TouchEventBase { + type: 'touchend'; + } + + interface TouchMoveEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any + > extends TouchEventBase { + type: 'touchmove'; + } + + interface TouchStartEvent< + TDelegateTarget = any, + TData = any, + TCurrentTarget = any + > extends TouchEventBase { + type: 'touchstart'; + } + + // #endregion + // region FocusEvent // #region FocusEvent @@ -6021,6 +6284,13 @@ $( "#checkMetaKey" ).click(function( event ) { keypress: KeyPressEvent; keyup: KeyUpEvent; + // TouchEvent + + touchcancel: TouchCancelEvent; + touchend: TouchEndEvent; + touchmove: TouchMoveEvent; + touchstart: TouchStartEvent; + // FocusEvent blur: BlurEvent; @@ -6266,6 +6536,7 @@ type _Event = Event; type _UIEvent = UIEvent; type _MouseEvent = MouseEvent; type _KeyboardEvent = KeyboardEvent; +type _TouchEvent = TouchEvent; type _FocusEvent = FocusEvent; // region ES5 compatibility From db83bc720086e202f8b24e37a71cab14a65db456 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Wed, 31 Oct 2018 11:38:35 -0400 Subject: [PATCH 089/792] [jquery] Don't use a separate type parameter for the type of `this` in event handlers. A separate type parameter is unnecessary as `this` and `currentTarget` reference the same object. --- types/jquery/JQuery.d.ts | 158 ++++++++++++++-------------- types/jquery/misc.d.ts | 15 ++- types/jquery/test/longdesc-tests.ts | 2 +- 3 files changed, 86 insertions(+), 89 deletions(-) diff --git a/types/jquery/JQuery.d.ts b/types/jquery/JQuery.d.ts index 83e27c6754..123fad3b34 100644 --- a/types/jquery/JQuery.d.ts +++ b/types/jquery/JQuery.d.ts @@ -1347,7 +1347,7 @@ $( "p" ).before( $( "b" ) ); TData>( eventType: TType, eventData: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach a handler to an event for the elements. @@ -1477,7 +1477,7 @@ $( "button" ).click(function() { */ bind( eventType: TType, - handler_preventBubble: JQuery.TypeEventHandler | + handler_preventBubble: JQuery.TypeEventHandler | false | null | undefined @@ -1507,7 +1507,7 @@ $( "div.test" ).bind({ }); ``` */ - bind(events: JQuery.TypeEventHandlers): this; + bind(events: JQuery.TypeEventHandlers): this; /** * Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. * @param eventData An object containing data that will be passed to the event handler. @@ -1521,7 +1521,7 @@ $( "div.test" ).bind({ * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ blur(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1537,7 +1537,7 @@ $( "div.test" ).bind({ $( "p" ).blur(); ``` */ - blur(handler?: JQuery.TypeEventHandler | + blur(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "change" JavaScript event, or trigger that event on an element. @@ -1552,7 +1552,7 @@ $( "p" ).blur(); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ change(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "change" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1611,7 +1611,7 @@ $( "input[type='text']" ).change(function() { }); ``` */ - change(handler?: JQuery.TypeEventHandler | + change(handler?: JQuery.TypeEventHandler | false): this; /** * Get the children of each element in the set of matched elements, optionally filtered by a selector. @@ -1865,7 +1865,7 @@ $( "#stop" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ click(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "click" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -1915,7 +1915,7 @@ $( "p" ).click(function() { $( "p" ).click(); ``` */ - click(handler?: JQuery.TypeEventHandler | + click(handler?: JQuery.TypeEventHandler | false): this; /** * Create a deep copy of the set of matched elements. @@ -2104,7 +2104,7 @@ $( "#frameDemo" ).contents().find( "a" ).css( "background-color", "#BADA55" ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ contextmenu(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "contextmenu" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -2158,7 +2158,7 @@ div.contextmenu(function() { ``` */ - contextmenu(handler?: JQuery.TypeEventHandler | + contextmenu(handler?: JQuery.TypeEventHandler | false): this; /** * Set one or more CSS properties for the set of matched elements. @@ -2620,7 +2620,7 @@ $( "button" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ dblclick(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "dblclick" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -2674,7 +2674,7 @@ divdbl.dblclick(function() { ``` */ - dblclick(handler?: JQuery.TypeEventHandler | + dblclick(handler?: JQuery.TypeEventHandler | false): this; /** * Set a timer to delay execution of subsequent items in the queue. @@ -2745,7 +2745,7 @@ $( "button" ).click(function() { selector: JQuery.Selector, eventType: TType, eventData: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. @@ -2861,7 +2861,7 @@ $( "button" ).click(function() { delegate( selector: JQuery.Selector, eventType: TType, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false ): this; /** @@ -2877,7 +2877,7 @@ $( "button" ).click(function() { * **Solution**: Change the method call to use `.on()` or `.off()`, the documentation for the old methods include specific instructions. In general, the `.bind()` and `.unbind()` methods can be renamed directly to `.on()` and `.off()` respectively since the argument orders are identical. */ delegate(selector: JQuery.Selector, - events: JQuery.TypeEventHandlers + events: JQuery.TypeEventHandlers ): this; /** * Execute the next function on the queue for the matched elements. @@ -4298,7 +4298,7 @@ $( "p span" ).first().addClass( "highlight" ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focus(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "focus" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -4350,7 +4350,7 @@ $( document ).ready(function() { }); ``` */ - focus(handler?: JQuery.TypeEventHandler | + focus(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "focusin" event. @@ -4365,7 +4365,7 @@ $( document ).ready(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focusin(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "focusin" event. * @param handler A function to execute each time the event is triggered. @@ -4405,7 +4405,7 @@ $( "p" ).focusin(function() { ``` */ - focusin(handler?: JQuery.TypeEventHandler | + focusin(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "focusout" JavaScript event. @@ -4420,7 +4420,7 @@ $( "p" ).focusin(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ focusout(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "focusout" JavaScript event. * @param handler A function to execute each time the event is triggered. @@ -4481,7 +4481,7 @@ $( "p" ) ``` */ - focusout(handler?: JQuery.TypeEventHandler | + focusout(handler?: JQuery.TypeEventHandler | false): this; /** * Retrieve one of the elements matched by the jQuery object. @@ -4998,9 +4998,9 @@ $( "td" ).hover( $( "td" ).off( "mouseenter mouseleave" ); ``` */ - hover(handlerIn: JQuery.TypeEventHandler | + hover(handlerIn: JQuery.TypeEventHandler | false, - handlerOut: JQuery.TypeEventHandler | + handlerOut: JQuery.TypeEventHandler | false): this; /** * Bind a single handler to the matched elements, to be executed when the mouse pointer enters or leaves the elements. @@ -5067,7 +5067,7 @@ $( "li" ) ``` */ - hover(handlerInOut: JQuery.TypeEventHandler | + hover(handlerInOut: JQuery.TypeEventHandler | false): this; /** * Set the HTML contents of each element in the set of matched elements. @@ -5882,7 +5882,7 @@ $( "li" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keydown(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -5954,7 +5954,7 @@ $( "#other" ).click(function() { ``` */ - keydown(handler?: JQuery.TypeEventHandler | + keydown(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. @@ -5969,7 +5969,7 @@ $( "#other" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keypress(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6041,7 +6041,7 @@ $( "#other" ).click(function() { ``` */ - keypress(handler?: JQuery.TypeEventHandler | + keypress(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. @@ -6056,7 +6056,7 @@ $( "#other" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ keyup(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6129,7 +6129,7 @@ $( "#other").click(function() { ``` */ - keyup(handler?: JQuery.TypeEventHandler | + keyup(handler?: JQuery.TypeEventHandler | false): this; /** * Reduce the set of matched elements to the final one in the set. @@ -6419,7 +6419,7 @@ $( "input" ).click(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mousedown(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6457,7 +6457,7 @@ $( "p" ) ``` */ - mousedown(handler?: JQuery.TypeEventHandler | + mousedown(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. @@ -6472,7 +6472,7 @@ $( "p" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseenter(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. * @param handler A function to execute each time the event is triggered. @@ -6553,7 +6553,7 @@ $( "div.enterleave" ) ``` */ - mouseenter(handler?: JQuery.TypeEventHandler | + mouseenter(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. @@ -6568,7 +6568,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseleave(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. * @param handler A function to execute each time the event is triggered. @@ -6647,7 +6647,7 @@ $( "div.enterleave" ) ``` */ - mouseleave(handler?: JQuery.TypeEventHandler | + mouseleave(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. @@ -6662,7 +6662,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mousemove(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6726,7 +6726,7 @@ $( "div" ).mousemove(function( event ) { ``` */ - mousemove(handler?: JQuery.TypeEventHandler | + mousemove(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. @@ -6741,7 +6741,7 @@ $( "div" ).mousemove(function( event ) { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseout(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6822,7 +6822,7 @@ $( "div.enterleave" ) ``` */ - mouseout(handler?: JQuery.TypeEventHandler | + mouseout(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. @@ -6837,7 +6837,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseover(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6918,7 +6918,7 @@ $( "div.enterleave" ) ``` */ - mouseover(handler?: JQuery.TypeEventHandler | + mouseover(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. @@ -6933,7 +6933,7 @@ $( "div.enterleave" ) * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ mouseup(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -6971,7 +6971,7 @@ $( "p" ) ``` */ - mouseup(handler?: JQuery.TypeEventHandler | + mouseup(handler?: JQuery.TypeEventHandler | false): this; /** * Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector. @@ -7306,7 +7306,7 @@ $( "body" ).off( "click", "p", foo ); */ off(events: string, selector: JQuery.Selector, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false): this; /** * Remove an event handler. @@ -7339,7 +7339,7 @@ $( "form" ).off( ".validator" ); */ off(events: string, selector_handler?: JQuery.Selector | - JQuery.TypeEventHandler | + JQuery.TypeEventHandler | false): this; /** * Remove an event handler. @@ -7349,7 +7349,7 @@ $( "form" ).off( ".validator" ); * @see \`{@link https://api.jquery.com/off/ }\` * @since 1.7 */ - off(events: JQuery.TypeEventHandlers, + off(events: JQuery.TypeEventHandlers, selector?: JQuery.Selector): this; /** * Remove an event handler. @@ -7539,7 +7539,7 @@ $( "*", document.body ).click(function( event ) { events: TType, selector: JQuery.Selector, data: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach an event handler function for one or more events to the selected elements. @@ -7556,7 +7556,7 @@ $( "*", document.body ).click(function( event ) { events: TType, selector: null | undefined, data: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach an event handler function for one or more events to the selected elements. @@ -7636,7 +7636,7 @@ $( "body" ).on( "click", "a", function( event ) { on( events: TType, selector: JQuery.Selector, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false ): this; /** @@ -7658,7 +7658,7 @@ $( "p" ).on( "click", { foo: "bar" }, myHandler ); TData>( events: TType, data: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach an event handler function for one or more events to the selected elements. @@ -7826,7 +7826,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { */ on( events: TType, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false ): this; /** @@ -7933,7 +7933,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @since 1.7 */ on( - events: JQuery.TypeEventHandlers, + events: JQuery.TypeEventHandlers, selector: JQuery.Selector, data: TData ): this; @@ -7948,7 +7948,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @since 1.7 */ on( - events: JQuery.TypeEventHandlers, + events: JQuery.TypeEventHandlers, selector: null | undefined, data: TData ): this; @@ -7961,7 +7961,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @see \`{@link https://api.jquery.com/on/ }\` * @since 1.7 */ - on(events: JQuery.TypeEventHandlers, + on(events: JQuery.TypeEventHandlers, selector: JQuery.Selector ): this; /** @@ -7973,7 +7973,7 @@ $( "#cart" ).on( "mouseenter mouseleave", function( event ) { * @since 1.7 */ on( - events: JQuery.TypeEventHandlers, + events: JQuery.TypeEventHandlers, data: TData ): this; /** @@ -8024,7 +8024,7 @@ $( "div.test" ).on({ ``` */ - on(events: JQuery.TypeEventHandlers): this; + on(events: JQuery.TypeEventHandlers): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -8040,7 +8040,7 @@ $( "div.test" ).on({ events: TType, selector: JQuery.Selector, data: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. @@ -8057,7 +8057,7 @@ $( "div.test" ).on({ events: TType, selector: null | undefined, data: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. @@ -8072,7 +8072,7 @@ $( "div.test" ).on({ one( events: TType, selector: JQuery.Selector, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false ): this; /** @@ -8087,7 +8087,7 @@ $( "div.test" ).on({ TData>( events: TType, data: TData, - handler: JQuery.TypeEventHandler + handler: JQuery.TypeEventHandler ): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. @@ -8179,7 +8179,7 @@ $(".target").one("click mouseenter", function() { */ one( events: TType, - handler: JQuery.TypeEventHandler| + handler: JQuery.TypeEventHandler| false ): this; /** @@ -8193,7 +8193,7 @@ $(".target").one("click mouseenter", function() { * @since 1.7 */ one( - events: JQuery.TypeEventHandlers, + events: JQuery.TypeEventHandlers, selector: JQuery.Selector, data: TData ): this; @@ -8208,7 +8208,7 @@ $(".target").one("click mouseenter", function() { * @since 1.7 */ one( - events: JQuery.TypeEventHandlers, + events: JQuery.TypeEventHandlers, selector: null | undefined, data: TData ): this; @@ -8221,7 +8221,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.TypeEventHandlers, + one(events: JQuery.TypeEventHandlers, selector: JQuery.Selector): this; /** * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. @@ -8232,7 +8232,7 @@ $(".target").one("click mouseenter", function() { * @since 1.7 */ one( - events: JQuery.TypeEventHandlers, + events: JQuery.TypeEventHandlers, data: TData ): this; /** @@ -8242,7 +8242,7 @@ $(".target").one("click mouseenter", function() { * @see \`{@link https://api.jquery.com/one/ }\` * @since 1.7 */ - one(events: JQuery.TypeEventHandlers): this; + one(events: JQuery.TypeEventHandlers): this; /** * Set the CSS outer height of each element in the set of matched elements. * @param value_function _@param_ `value_function` @@ -10000,7 +10000,7 @@ $( "button" ).on( "click", function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ resize(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -10018,7 +10018,7 @@ $( window ).resize(function() { }); ``` */ - resize(handler?: JQuery.TypeEventHandler | + resize(handler?: JQuery.TypeEventHandler | false): this; /** * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. @@ -10033,7 +10033,7 @@ $( window ).resize(function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ scroll(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -10083,7 +10083,7 @@ $( window ).scroll(function() { ``` */ - scroll(handler?: JQuery.TypeEventHandler | + scroll(handler?: JQuery.TypeEventHandler | false): this; /** * Set the current horizontal position of the scroll bar for each of the set of matched elements. @@ -10258,7 +10258,7 @@ $( "p:last" ).text( "scrollTop:" + p.scrollTop() ); * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ select(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "select" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -10307,7 +10307,7 @@ $( ":input" ).select(function() { $( "input" ).select(); ``` */ - select(handler?: JQuery.TypeEventHandler | + select(handler?: JQuery.TypeEventHandler | false): this; /** * Encode a set of form elements as a string for submission. @@ -11279,7 +11279,7 @@ $( "#toggle" ).on( "click", function() { * **Solution**: Instead of `.click(fn)` use `.on("click", fn)`. Instead of `.click()` use `.trigger("click")`. */ submit(eventData: TData, - handler: JQuery.TypeEventHandler): this; + handler: JQuery.TypeEventHandler): this; /** * Bind an event handler to the "submit" JavaScript event, or trigger that event on an element. * @param handler A function to execute each time the event is triggered. @@ -11348,7 +11348,7 @@ $( "form" ).submit(function() { $( "form:first" ).submit(); ``` */ - submit(handler?: JQuery.TypeEventHandler | + submit(handler?: JQuery.TypeEventHandler | false): this; /** * Set the content of each element in the set of matched elements to the specified text. @@ -11969,7 +11969,7 @@ $( "p" ).unbind( "click", foo ); // ... foo will no longer be called. ``` */ unbind(event: string, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false ): this; /** @@ -12064,7 +12064,7 @@ $( "body" ).undelegate( "p", "click", foo ); */ undelegate(selector: JQuery.Selector, eventType: string, - handler: JQuery.TypeEventHandler | + handler: JQuery.TypeEventHandler | false ): this; /** @@ -12085,7 +12085,7 @@ $( "body" ).undelegate( "p", "click", foo ); */ undelegate(selector: JQuery.Selector, eventType_events: string | - JQuery.TypeEventHandlers): this; + JQuery.TypeEventHandlers): this; /** * Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements. * @param namespace A selector which will be used to filter the event results. diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index dd05435043..553f3a58ed 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -6314,20 +6314,18 @@ $( "#checkMetaKey" ).click(function( event ) { TData, TCurrentTarget, TTarget, - TContext, TType extends keyof TypeToTriggeredEventMap - > = EventHandlerBase[TType]>; + > = EventHandlerBase[TType]>; interface TypeEventHandlers< TDelegateTarget, TData, TCurrentTarget, - TTarget, - TContext - > extends _TypeEventHandlers { + TTarget + > extends _TypeEventHandlers { // No idea why it's necessary to include `object` in the union but otherwise TypeScript complains that // derived types of Event are not assignable to Event. - [type: string]: TypeEventHandler | + [type: string]: TypeEventHandler | false | undefined | object; @@ -6337,11 +6335,10 @@ $( "#checkMetaKey" ).click(function( event ) { TDelegateTarget, TData, TCurrentTarget, - TTarget, - TContext + TTarget > = { [TType in keyof TypeToTriggeredEventMap]?: - TypeEventHandler | + TypeEventHandler | false | object; }; diff --git a/types/jquery/test/longdesc-tests.ts b/types/jquery/test/longdesc-tests.ts index f3cf559638..8c5382f904 100644 --- a/types/jquery/test/longdesc-tests.ts +++ b/types/jquery/test/longdesc-tests.ts @@ -538,7 +538,7 @@ function longdesc() { $('#foo').slideUp(300).delay(800).fadeIn(400); } - function delegate_0(elements: HTMLElement[], selector: string, events: string, data: any, handler: JQuery.TypeEventHandler) { + function delegate_0(elements: HTMLElement[], selector: string, events: string, data: any, handler: JQuery.TypeEventHandler) { // jQuery 1.4.3+ $(elements).delegate(selector, events, data, handler); // jQuery 1.7+ From 33c6e58f6e3d5d1bcc9d02710d7f7d634645337e Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Thu, 1 Nov 2018 10:01:29 -0400 Subject: [PATCH 090/792] [jquery] Add missing `TTarget` type parameter to touch events. --- types/jquery/misc.d.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/types/jquery/misc.d.ts b/types/jquery/misc.d.ts index 553f3a58ed..481b79e037 100644 --- a/types/jquery/misc.d.ts +++ b/types/jquery/misc.d.ts @@ -5722,8 +5722,9 @@ $( "#checkMetaKey" ).click(function( event ) { interface TouchEventBase< TDelegateTarget = any, TData = any, - TCurrentTarget = any - > extends UIEventBase { + TCurrentTarget = any, + TTarget = any + > extends UIEventBase { /** * The other DOM element involved in the event, if any. * @see \`{@link https://api.jquery.com/event.relatedTarget/ }\` @@ -5948,32 +5949,36 @@ $( "#checkMetaKey" ).click(function( event ) { interface TouchCancelEvent< TDelegateTarget = any, TData = any, - TCurrentTarget = any - > extends TouchEventBase { + TCurrentTarget = any, + TTarget = any + > extends TouchEventBase { type: 'touchcancel'; } interface TouchEndEvent< TDelegateTarget = any, TData = any, - TCurrentTarget = any - > extends TouchEventBase { + TCurrentTarget = any, + TTarget = any + > extends TouchEventBase { type: 'touchend'; } interface TouchMoveEvent< TDelegateTarget = any, TData = any, - TCurrentTarget = any - > extends TouchEventBase { + TCurrentTarget = any, + TTarget = any + > extends TouchEventBase { type: 'touchmove'; } interface TouchStartEvent< TDelegateTarget = any, TData = any, - TCurrentTarget = any - > extends TouchEventBase { + TCurrentTarget = any, + TTarget = any + > extends TouchEventBase { type: 'touchstart'; } @@ -6286,10 +6291,10 @@ $( "#checkMetaKey" ).click(function( event ) { // TouchEvent - touchcancel: TouchCancelEvent; - touchend: TouchEndEvent; - touchmove: TouchMoveEvent; - touchstart: TouchStartEvent; + touchcancel: TouchCancelEvent; + touchend: TouchEndEvent; + touchmove: TouchMoveEvent; + touchstart: TouchStartEvent; // FocusEvent From e573d98516efcf5da8773cc97d337475405dc291 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Thu, 1 Nov 2018 10:39:42 -0400 Subject: [PATCH 091/792] [jquery] Add tests for `JQuery.TypeEventHandlers`. --- types/jquery/jquery-tests.ts | 161 +++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 069e8613d6..c533f1b235 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -7862,6 +7862,167 @@ function JQuery_Event() { } } +function JQuery_TypeEventHandlers() { + const events: JQuery.TypeEventHandlers = { + change(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ChangeEvent + event; + }, + resize(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ResizeEvent + event; + }, + scroll(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ScrollEvent + event; + }, + select(event) { + // $ExpectType HTMLElement + this; + // $ExpectType SelectEvent + event; + }, + submit(event) { + // $ExpectType HTMLElement + this; + // $ExpectType SubmitEvent + event; + }, + click(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ClickEvent + event; + }, + contextmenu(event) { + // $ExpectType HTMLElement + this; + // $ExpectType ContextMenuEvent + event; + }, + dblclick(event) { + // $ExpectType HTMLElement + this; + // $ExpectType DoubleClickEvent + event; + }, + mousedown(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseDownEvent + event; + }, + mouseenter(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseEnterEvent + event; + }, + mouseleave(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseLeaveEvent + event; + }, + mousemove(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseMoveEvent + event; + }, + mouseout(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseOutEvent + event; + }, + mouseover(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseOverEvent + event; + }, + mouseup(event) { + // $ExpectType HTMLElement + this; + // $ExpectType MouseUpEvent + event; + }, + keydown(event) { + // $ExpectType HTMLElement + this; + // $ExpectType KeyDownEvent + event; + }, + keypress(event) { + // $ExpectType HTMLElement + this; + // $ExpectType KeyPressEvent + event; + }, + keyup(event) { + // $ExpectType HTMLElement + this; + // $ExpectType KeyUpEvent + event; + }, + touchcancel(event) { + // $ExpectType HTMLElement + this; + // $ExpectType TouchCancelEvent + event; + }, + touchend(event) { + // $ExpectType HTMLElement + this; + // $ExpectType TouchEndEvent + event; + }, + touchmove(event) { + // $ExpectType HTMLElement + this; + // $ExpectType TouchMoveEvent + event; + }, + touchstart(event) { + // $ExpectType HTMLElement + this; + // $ExpectType TouchStartEvent + event; + }, + blur(event) { + // $ExpectType HTMLElement + this; + // $ExpectType BlurEvent + event; + }, + focus(event) { + // $ExpectType HTMLElement + this; + // $ExpectType FocusEvent + event; + }, + focusin(event) { + // $ExpectType HTMLElement + this; + // $ExpectType FocusInEvent + event; + }, + focusout(event) { + // $ExpectType HTMLElement + this; + // $ExpectType FocusOutEvent + event; + } + }; +} + function JQuery_EventExtensions() { function special() { jQuery.event.special.multiclick = { From bf2beee34cc2b64128bbbde858a476fcaba976e2 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sat, 24 Nov 2018 09:45:54 -0500 Subject: [PATCH 092/792] [jquery] Fix no-angle-bracket-type-assertion violations. --- types/jquery/test/example-tests.ts | 2 +- types/jquery/test/longdesc-tests.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 673e549c31..77d412f8e1 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -1578,7 +1578,7 @@ function examples() { function event_related_target_0() { $('a').mouseout(function(event) { - alert(( event.relatedTarget).nodeName); // "DIV" + alert((event.relatedTarget as HTMLElement).nodeName); // "DIV" }); } diff --git a/types/jquery/test/longdesc-tests.ts b/types/jquery/test/longdesc-tests.ts index 8c5382f904..e1ee36a575 100644 --- a/types/jquery/test/longdesc-tests.ts +++ b/types/jquery/test/longdesc-tests.ts @@ -886,7 +886,7 @@ function longdesc() { var currentRequests: JQuery.PlainObject = {}; $.ajaxPrefilter(function(options, originalOptions, jqXHR) { - if (( options).abortOnRetry) { + if ((options as any).abortOnRetry) { if (currentRequests[options.url!]) { currentRequests[options.url!].abort(); } @@ -1297,7 +1297,7 @@ function longdesc() { return $.css(elem, borderRadius!); }, set: function(elem, value) { - ( elem.style)[borderRadius!] = value; + (elem.style as any)[borderRadius!] = value; }, }; } From 1bcbf71b93f09c4a7f29d7f60a18c6dc99d6aa4d Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sat, 24 Nov 2018 15:54:45 +0100 Subject: [PATCH 093/792] Fix error in list type --- types/prompts/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index 7aa3f2ea63..a10a7ba243 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/terkelg/prompts // Definitions by: Berkay GURSOY // Daniel Perez Alvarez +// Kamontat Chantrachirathumrong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -47,6 +48,7 @@ declare namespace prompts { interface Choice { title: string; value: string; + disable?: boolean; } interface Options { @@ -58,7 +60,7 @@ declare namespace prompts { type: ValueOrFunc; name: ValueOrFunc; message?: ValueOrFunc; - initial?: string; + initial?: string | number; style?: string; format?: PrevCaller; validate?: PrevCaller; From a34223bc90cabd779bcbb14c2d9685206c52d87d Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sat, 24 Nov 2018 15:57:20 +0100 Subject: [PATCH 094/792] [release] Increase prompts version 1.2 --- types/prompts/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index a10a7ba243..447d67d557 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for prompts 1.1 +// Type definitions for prompts 1.2 // Project: https://github.com/terkelg/prompts // Definitions by: Berkay GURSOY // Daniel Perez Alvarez From a2c196471f30c373a6127ea47bc23c7973f0a454 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sat, 24 Nov 2018 16:00:36 +0100 Subject: [PATCH 095/792] [improve] Add boolean as initial message --- types/prompts/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index 447d67d557..d68f63af8e 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -60,7 +60,7 @@ declare namespace prompts { type: ValueOrFunc; name: ValueOrFunc; message?: ValueOrFunc; - initial?: string | number; + initial?: string | number | boolean; style?: string; format?: PrevCaller; validate?: PrevCaller; From 218607fa1be6d4394178f76e9bc490fcc46e38b5 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sat, 24 Nov 2018 16:06:46 +0100 Subject: [PATCH 096/792] [improve] Add falsy type to skip the question --- types/prompts/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index d68f63af8e..e4e2fbca80 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -57,7 +57,7 @@ declare namespace prompts { } interface PromptObject { - type: ValueOrFunc; + type: ValueOrFunc | Falsy; name: ValueOrFunc; message?: ValueOrFunc; initial?: string | number | boolean; @@ -86,6 +86,8 @@ declare namespace prompts { values: Answers, prompt: PromptObject ) => R; + + type Falsy = false | null | undefined; type ValueOrFunc = T | PrevCaller; } From e067afd74c6a54eb618b82b92f195b9a21b7f0d8 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sat, 24 Nov 2018 10:22:29 -0500 Subject: [PATCH 097/792] Disable no-angle-bracket-type-assertion rule. --- types/angular-agility/tslint.json | 3 ++- types/angular-locker/tslint.json | 3 ++- types/angular-odata-resources/tslint.json | 3 ++- types/angular-ui-tree/tslint.json | 3 ++- types/angularfire/tslint.json | 3 ++- types/bootstrap-slider/tslint.json | 5 ++++- types/datatables.net/tslint.json | 7 ++++++- types/devexpress-web/v172/tslint.json | 3 ++- types/devexpress-web/v181/tslint.json | 3 ++- types/ej.web.all/tslint.json | 3 ++- types/gridstack/tslint.json | 3 ++- types/highcharts/tslint.json | 3 ++- types/intl-tel-input/v13/tslint.json | 3 ++- types/jquery.colorpicker/tslint.json | 3 ++- types/jquery.fancytree/tslint.json | 3 ++- types/jquery.pjax/tslint.json | 3 ++- types/kendo-ui/tslint.json | 3 ++- types/ng-cordova/tslint.json | 3 ++- types/ng-flow/tslint.json | 3 ++- types/ng-grid/tslint.json | 3 ++- types/openui5/tslint.json | 3 ++- types/q/tslint.json | 3 ++- types/q/v0/tslint.json | 3 ++- types/qtip2/tslint.json | 3 ++- types/sammy/tslint.json | 3 ++- types/segment-analytics/tslint.json | 3 ++- types/selectize/tslint.json | 3 ++- types/space-pen/tslint.json | 3 ++- types/toastr/tslint.json | 3 ++- 29 files changed, 64 insertions(+), 29 deletions(-) diff --git a/types/angular-agility/tslint.json b/types/angular-agility/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/angular-agility/tslint.json +++ b/types/angular-agility/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/angular-locker/tslint.json b/types/angular-locker/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/angular-locker/tslint.json +++ b/types/angular-locker/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/angular-odata-resources/tslint.json b/types/angular-odata-resources/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/angular-odata-resources/tslint.json +++ b/types/angular-odata-resources/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/angular-ui-tree/tslint.json b/types/angular-ui-tree/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/angular-ui-tree/tslint.json +++ b/types/angular-ui-tree/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/angularfire/tslint.json b/types/angularfire/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/angularfire/tslint.json +++ b/types/angularfire/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/bootstrap-slider/tslint.json b/types/bootstrap-slider/tslint.json index f93cf8562a..1c36270d47 100644 --- a/types/bootstrap-slider/tslint.json +++ b/types/bootstrap-slider/tslint.json @@ -1,3 +1,6 @@ { - "extends": "dtslint/dt.json" + "extends": "dtslint/dt.json", + "rules": { + "no-angle-bracket-type-assertion": false + } } diff --git a/types/datatables.net/tslint.json b/types/datatables.net/tslint.json index 3db14f85ea..2b6ccb9109 100644 --- a/types/datatables.net/tslint.json +++ b/types/datatables.net/tslint.json @@ -1 +1,6 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "no-angle-bracket-type-assertion": false + } +} \ No newline at end of file diff --git a/types/devexpress-web/v172/tslint.json b/types/devexpress-web/v172/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/devexpress-web/v172/tslint.json +++ b/types/devexpress-web/v172/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/devexpress-web/v181/tslint.json b/types/devexpress-web/v181/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/devexpress-web/v181/tslint.json +++ b/types/devexpress-web/v181/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/ej.web.all/tslint.json b/types/ej.web.all/tslint.json index 35e3f27cc8..0615bdcb0e 100644 --- a/types/ej.web.all/tslint.json +++ b/types/ej.web.all/tslint.json @@ -37,6 +37,7 @@ "radix": false, "prefer-for-of": false, "one-line": false, - "no-unnecessary-type-assertion": false + "no-unnecessary-type-assertion": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/gridstack/tslint.json b/types/gridstack/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/gridstack/tslint.json +++ b/types/gridstack/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/highcharts/tslint.json b/types/highcharts/tslint.json index cfc8218eab..c663b9324a 100644 --- a/types/highcharts/tslint.json +++ b/types/highcharts/tslint.json @@ -9,6 +9,7 @@ "no-declare-current-package": false, "no-object-literal-type-assertion": false, "no-self-import": false, - "no-unnecessary-generics": false + "no-unnecessary-generics": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/intl-tel-input/v13/tslint.json b/types/intl-tel-input/v13/tslint.json index b6afb8acee..d2632b3e92 100644 --- a/types/intl-tel-input/v13/tslint.json +++ b/types/intl-tel-input/v13/tslint.json @@ -75,6 +75,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/jquery.colorpicker/tslint.json b/types/jquery.colorpicker/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/jquery.colorpicker/tslint.json +++ b/types/jquery.colorpicker/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/jquery.fancytree/tslint.json b/types/jquery.fancytree/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/jquery.fancytree/tslint.json +++ b/types/jquery.fancytree/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/jquery.pjax/tslint.json b/types/jquery.pjax/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/jquery.pjax/tslint.json +++ b/types/jquery.pjax/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/kendo-ui/tslint.json b/types/kendo-ui/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/kendo-ui/tslint.json +++ b/types/kendo-ui/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/ng-cordova/tslint.json b/types/ng-cordova/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/ng-cordova/tslint.json +++ b/types/ng-cordova/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/ng-flow/tslint.json b/types/ng-flow/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/ng-flow/tslint.json +++ b/types/ng-flow/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/ng-grid/tslint.json b/types/ng-grid/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/ng-grid/tslint.json +++ b/types/ng-grid/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/openui5/tslint.json b/types/openui5/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/openui5/tslint.json +++ b/types/openui5/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/q/tslint.json b/types/q/tslint.json index 0bded8e292..4af8abbc8d 100644 --- a/types/q/tslint.json +++ b/types/q/tslint.json @@ -7,6 +7,7 @@ "no-unnecessary-type-assertion": false, "prefer-declare-function": false, "strict-export-declare-modifiers": false, - "unified-signatures": false + "unified-signatures": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/q/v0/tslint.json b/types/q/v0/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/q/v0/tslint.json +++ b/types/q/v0/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/qtip2/tslint.json b/types/qtip2/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/qtip2/tslint.json +++ b/types/qtip2/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/sammy/tslint.json b/types/sammy/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/sammy/tslint.json +++ b/types/sammy/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/segment-analytics/tslint.json b/types/segment-analytics/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/segment-analytics/tslint.json +++ b/types/segment-analytics/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/selectize/tslint.json b/types/selectize/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/selectize/tslint.json +++ b/types/selectize/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/space-pen/tslint.json b/types/space-pen/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/space-pen/tslint.json +++ b/types/space-pen/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } diff --git a/types/toastr/tslint.json b/types/toastr/tslint.json index a41bf5d19a..67293bd146 100644 --- a/types/toastr/tslint.json +++ b/types/toastr/tslint.json @@ -74,6 +74,7 @@ "typedef-whitespace": false, "unified-signatures": false, "void-return": false, - "whitespace": false + "whitespace": false, + "no-angle-bracket-type-assertion": false } } From dcda399637f7d78d7a7dd1c6ed1f5ccf01693a28 Mon Sep 17 00:00:00 2001 From: BamButz Date: Sun, 25 Nov 2018 12:25:56 +0100 Subject: [PATCH 098/792] Adding types for "hyper-aws4" --- types/hyper-aws4/hyper-aws4-tests.ts | 12 ++++++++++++ types/hyper-aws4/index.d.ts | 25 +++++++++++++++++++++++++ types/hyper-aws4/tsconfig.json | 23 +++++++++++++++++++++++ types/hyper-aws4/tslint.json | 1 + 4 files changed, 61 insertions(+) create mode 100644 types/hyper-aws4/hyper-aws4-tests.ts create mode 100644 types/hyper-aws4/index.d.ts create mode 100644 types/hyper-aws4/tsconfig.json create mode 100644 types/hyper-aws4/tslint.json diff --git a/types/hyper-aws4/hyper-aws4-tests.ts b/types/hyper-aws4/hyper-aws4-tests.ts new file mode 100644 index 0000000000..14caa34a9f --- /dev/null +++ b/types/hyper-aws4/hyper-aws4-tests.ts @@ -0,0 +1,12 @@ +import { sign, Request } from "hyper-aws4"; + +const signOption: Request = { + url: "https://us-west-1.hyper.sh/version", + method: "GET", + credential: { + accessKey: "6DPLADBPWYXDUVXLX34EJXBL", + secretKey: "2ldD1Yz0nzATl9vvagBwYTjglXBjVOWU8gV8aMm5" + } +}; + +sign(signOption); diff --git a/types/hyper-aws4/index.d.ts b/types/hyper-aws4/index.d.ts new file mode 100644 index 0000000000..bf2a0fafa8 --- /dev/null +++ b/types/hyper-aws4/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for hyper-aws4 1.1 +// Project: https://github.com/Tim-Zhang/hyper-aws4#readme +// Definitions by: BamButz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Credentials { + accessKey: string; + secretKey: string; +} + +export interface Header { + [header: string]: string; +} + +export type HttpMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; + +export interface Request { + url: string; + method?: HttpMethods; + body?: string; + headers?: Header; + credential?: Credentials; +} + +export function sign(request: Request, credential?: Credentials): Header; diff --git a/types/hyper-aws4/tsconfig.json b/types/hyper-aws4/tsconfig.json new file mode 100644 index 0000000000..6df2d811c1 --- /dev/null +++ b/types/hyper-aws4/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "hyper-aws4-tests.ts" + ] +} diff --git a/types/hyper-aws4/tslint.json b/types/hyper-aws4/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hyper-aws4/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 02da4b8731282cb35ed274cc337fcc64fd53f619 Mon Sep 17 00:00:00 2001 From: izmhr Date: Sun, 25 Nov 2018 20:40:27 +0900 Subject: [PATCH 099/792] Completely new definitions for SkyWay@1.1.17 and TypeScript@3.0 --- types/skyway/index.d.ts | 327 ++++++++++++++++------------------- types/skyway/skyway-tests.ts | 51 +++--- 2 files changed, 171 insertions(+), 207 deletions(-) diff --git a/types/skyway/index.d.ts b/types/skyway/index.d.ts index eb73937178..8cdbec4a8e 100644 --- a/types/skyway/index.d.ts +++ b/types/skyway/index.d.ts @@ -1,185 +1,154 @@ -// Type definitions for SkyWay -// Project: http://nttcom.github.io/skyway/ +// Type definitions for SkyWay@1.1.17 +// Project: https://github.com/skyway/skyway-js-sdk +// Based on Documentation for skyway-js-doc: https://github.com/skyway/skyway-js-sdk-doc // Definitions by: Toshiya Nakakura +// Atsushi Izumihara // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 -/// - -declare namespace PeerJs{ - interface PeerJSOption{ - key?: string; - host?: string; - port?: number; - path?: string; - secure?: boolean; - turn?: boolean; - config?: RTCPeerConnectionConfig; - debug?: number; - } - - interface PeerConnectOption{ - label?: string; - metadata?: any; - serialization?: string; - reliable?: boolean; - } - - interface DataConnection{ - send(data: any): void; - close(): void; - on(event: string, cb: ()=>void): void; - on(event: 'data', cb: (data: any)=>void): void; - on(event: 'open', cb: ()=>void): void; - on(event: 'close', cb: ()=>void): void; - on(event: 'error', cb: (err: any)=>void): void; - off(event: string, fn: Function, once?: boolean): void; - bufferSize: number; - dataChannel: RTCDataChannel; - label: string; - metadata: any; - open: boolean; - peerConnection: any; - peer: string; - reliable: boolean; - serialization: string; - type: string; - } - - interface MediaConnection{ - answer(stream?: any): void; - close(): void; - on(event: string, cb: ()=>void): void; - on(event: 'stream', cb: (stream: any)=>void): void; - on(event: 'close', cb: ()=>void): void; - on(event: 'error', cb: (err: any)=>void): void; - off(event: string, fn: Function, once?: boolean): void; - open: boolean; - metadata: any; - peer: string; - type: string; - } - - interface utilSupportsObj { - audioVideo: boolean; - data: boolean; - binary: boolean; - reliable: boolean; - } - - interface util{ - browser: string; - supports: utilSupportsObj; - } - - export interface Peer{ - /** - * - * @param id The brokering ID of the remote peer (their peer.id). - * @param options for specifying details about Peer Connection - */ - connect(id: string, options?: PeerJs.PeerConnectOption): PeerJs.DataConnection; - /** - * Connects to the remote peer specified by id and returns a data connection. - * @param id The brokering ID of the remote peer (their peer.id). - * @param stream The caller's media stream - */ - call(id: string, stream: any): PeerJs.MediaConnection; - /** - * Calls the remote peer specified by id and returns a media connection. - * @param event Event name - * @param cb Callback Function - */ - on(event: string, cb: ()=>void): void; - /** - * Emitted when a connection to the PeerServer is established. - * @param event Event name - * @param cb id is the brokering ID of the peer - */ - on(event: 'open', cb: (id: string)=>void): void; - /** - * Emitted when a new data connection is established from a remote peer. - * @param event Event name - * @param cb Callback Function - */ - on(event: 'connection', cb: (dataConnection: PeerJs.DataConnection)=>void): void; - /** - * Emitted when a remote peer attempts to call you. - * @param event Event name - * @param cb Callback Function - */ - on(event: 'call', cb: (mediaConnection: PeerJs.MediaConnection)=>void): void; - /** - * Emitted when the peer is destroyed and can no longer accept or create any new connections. - * @param event Event name - * @param cb Callback Function - */ - on(event: 'close', cb: ()=>void): void; - /** - * Emitted when the peer is disconnected from the signalling server - * @param event Event name - * @param cb Callback Function - */ - on(event: 'disconnected', cb: ()=>void): void; - /** - * Errors on the peer are almost always fatal and will destroy the peer. - * @param event Event name - * @param cb Callback Function - */ - on(event: 'error', cb: (err: any)=>void): void; - /** - * Remove event listeners.(EventEmitter3) - * @param {String} event The event we want to remove. - * @param {Function} fn The listener that we need to find. - * @param {Boolean} once Only remove once listeners. - */ - off(event: string, fn: Function, once?: boolean): void; - /** - * Close the connection to the server, leaving all existing data and media connections intact. - */ - disconnect(): void; - /** - * Close the connection to the server and terminate all existing connections. - */ - destroy(): void; - /** - * Get a list of available peer IDs - * @param callback - */ - listAllPeers(callback: (peerIds: Array)=>void): void; - - /** - * The brokering ID of this peer - */ - id: string; - /** - * A hash of all connections associated with this peer, keyed by the remote peer's ID. - */ - connections: any; - /** - * false if there is an active connection to the PeerServer. - */ - disconnected: boolean; - /** - * true if this peer and all of its connections can no longer be used. - */ - destroyed: boolean; - } +interface Options { + key: string; + debug?: number; + turn?: boolean; + credential?: Credential; + config?: RTCConfiguration; } -declare var Peer: { - prototype: RTCIceServer; - /** - * A peer can connect to other peers and listen for connections. - * @param id Other peers can connect to this peer using the provided ID. - * If no ID is given, one will be generated by the brokering server. - * @param options for specifying details about PeerServer - */ - new (id: string, options?: PeerJs.PeerJSOption): PeerJs.Peer; +interface Credential { + timestamp?: number; + ttl?: number; + authToken?: string; +} - /** - * A peer can connect to other peers and listen for connections. - * @param options for specifying details about PeerServer - */ - new (options: PeerJs.PeerJSOption): PeerJs.Peer; -}; +interface CallOptions { + metadata?: any; + videoBandWidth?: number; + audioBandwidth?: number; + videoCodec?: string; + audioCodec?: string; + videoReceiveEnabled?: boolean; + audioReceiveEnabled?: boolean; + label?: string; +} + +interface ConnectOptions { + metadata?: any; + serialization?: string; + dcInit?: RTCDataChannelInit; + label?: string; +} + +interface RoomOptions { + mode?: string; + stream?: MediaStream; + videoBandwidth?: number; + audioBandwidth?: number; + videoCodec?: string; + audioCodec?: string; + videoReceiveEnabled?: boolean; + audioReceiveEnabled?: boolean; +} + +interface AnswerOptions { + videoBandwidth?: number; + audioBandwidth?: number; + videoCodec?: string; + audioCodec?: string; +} + +declare class Peer { + constructor(id: string, options: Options); + constructor(options: Options); + + connections: any; + id: string; + open: boolean; + rooms: any; + + call(peerId: string, stream?: MediaStream, options?: CallOptions): MediaConnection | undefined; + connect(peerId: string, options?: ConnectOptions): DataConnection | undefined; + destroy(): undefined; + disconnect(): undefined; + joinRoom(roomName: string, roomOptions?: RoomOptions): SFURoom | MeshRoom | undefined | null; + listAllPeers(cb: (peerIds: Array) => void): void; + updateCredential(newCredential: Credential): undefined; + + on(event: string, cb: (ret: any) => void): void; + on(event: 'open', cb: (id: string) => void): void; + on(event: 'call', cb: (call: MediaConnection) => void): void; + on(event: 'close', cb: () => void): void; + on(event: 'connection', cb: (connection: DataConnection) => void): void; + on(event: 'disconnected', cb: (id: string) => void): void; + on(event: 'error', cb: (err: any) => void): void; +} + +declare class MediaConnection { + metadata: any; + open: boolean; + remoteId: string; + peer: string; + + answer(stream: MediaStream, options?: AnswerOptions): undefined; + close(): void | undefined; + replaceStream(stream: MediaStream): undefined; + + on(event: string, cb: () => void): void; + on(event: 'stream', cb: (stream: MediaStream) => void): void; + on(event: 'close', cb: () => void): void; + on(event: 'removeStream', cb: (reamoteStream: MediaStream) => void): void; +} + +declare class DataConnection { + metadata: any; + open: boolean; + remoteId: string; + peer: string; + + send(data: any): void; + close(): void | undefined; + + on(event: string, cb: () => void): void; + on(event: 'data', cb: (data: any) => void): void; + on(event: 'close', cb: () => void): void; +} + +interface DataObject { + src: string; + data: any; +} + +declare class MeshRoom { + close(): undefined; + getLog(): undefined; + replaceStream(stream: MediaSource): undefined; + send(data: any): undefined; + + on(event: string, cb: () => void): void; + on(event: 'open', cb: () => void): void; + on(event: 'peerJoin', cb: (peerId: string) => void): void; + on(event: 'peerLeave', cb: (peerId: string) => void): void; + on(event: 'log', cb: (logs: Array) => void): void; + once(event: 'log', cb: (logs: Array) => void): void; + on(event: 'stream', cb: (stream: MediaStream) => void): void; + on(event: 'data', cb: (object: DataObject) => void): void; + on(event: 'close', cb: () => void): void; + on(event: 'removeStream', cb: (stream: MediaStream) => void): void; +} + +declare class SFURoom { + close(): undefined; + getLog(): undefined; + replaceStream(stream: MediaSource): undefined; + send(data: any): undefined; + + on(event: string, cb: () => void): void; + on(event: 'open', cb: () => void): void; + on(event: 'peerJoin', cb: (peerId: string) => void): void; + on(event: 'peerLeave', cb: (peerId: string) => void): void; + on(event: 'log', cb: (logs: Array) => void): void; + once(event: 'log', cb: (logs: Array) => void): void; + on(event: 'stream', cb: (stream: MediaStream) => void): void; + on(event: 'data', cb: (object: DataObject) => void): void; + on(event: 'close', cb: () => void): void; + on(event: 'removeStream', cb: (stream: MediaStream) => void): void; +} diff --git a/types/skyway/skyway-tests.ts b/types/skyway/skyway-tests.ts index 2731192f75..46ee924bcb 100644 --- a/types/skyway/skyway-tests.ts +++ b/types/skyway/skyway-tests.ts @@ -1,44 +1,39 @@ -var peerByOption: PeerJs.Peer = new Peer({ +/// + +const peerByOption: Peer = new Peer({ key: 'peerKey', - debug: 3, + debug: 3 }); -peerByOption.listAllPeers(function(items){ - for(var i in items){ - console.log(decodeURI(items[i])); +peerByOption.listAllPeers((items) => { + for (let item in items) { + console.log(decodeURI(items[item])); } }); -var peerById: PeerJs.Peer = new Peer("peerid"); +const peerByIdAndOption: Peer = new Peer('peerid', { + key: 'peerKey', + debug: 3 +}); -var peerByIdAndOption: PeerJs.Peer = new Peer( - "peerId", - { - key: 'peerKey', - debug: 3, - }); - -var id = peerByOption.id; -var connections = peerByOption.connections; -var flag = peerByOption.disconnected; -flag = peerByOption.destroyed; +let id = peerByOption.id; +let connections = peerByOption.connections; peerByOption.disconnect(); peerByOption.destroy(); -var connection = peerById.connect("id", { +let connection = peerByOption.connect("id", { label: 'chat', serialization: 'none', - metadata: {message: 'hi i want to chat with you!'} + metadata: { message: 'hi i want to chat with you!' } }); -var call = peerById.call('callto-id', (window).localStream); +let call = peerByOption.call('callto-id', (window as any).localStream); -var openHandler=()=> console.log("open"); -peerById.on("open", openHandler); -peerById.on("connection", (c)=> console.log("connection")); -peerById.on("call", (media)=> console.log("call")); -peerById.on("close", ()=> console.log("close")); -peerById.on("disconnected", ()=> console.log("disconnected")); -peerById.on("error", (err)=> console.log(err)); -peerById.off("open", openHandler); +let openHandler = () => console.log("open"); +peerByOption.on("open", openHandler); +peerByOption.on("connection", (c) => console.log("connection")); +peerByOption.on("call", (media) => console.log("call")); +peerByOption.on("close", () => console.log("close")); +peerByOption.on("disconnected", () => console.log("disconnected")); +peerByOption.on("error", (err) => console.log(err)); From 0577b97e084594414b2db82616c72e91f04793ea Mon Sep 17 00:00:00 2001 From: izmhr Date: Sun, 25 Nov 2018 21:04:01 +0900 Subject: [PATCH 100/792] checking npm test error --- types/skyway/index.d.ts | 1 - types/skyway/skyway-tests.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/types/skyway/index.d.ts b/types/skyway/index.d.ts index 8cdbec4a8e..044768a08e 100644 --- a/types/skyway/index.d.ts +++ b/types/skyway/index.d.ts @@ -1,6 +1,5 @@ // Type definitions for SkyWay@1.1.17 // Project: https://github.com/skyway/skyway-js-sdk -// Based on Documentation for skyway-js-doc: https://github.com/skyway/skyway-js-sdk-doc // Definitions by: Toshiya Nakakura // Atsushi Izumihara // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/skyway/skyway-tests.ts b/types/skyway/skyway-tests.ts index 46ee924bcb..702a05e709 100644 --- a/types/skyway/skyway-tests.ts +++ b/types/skyway/skyway-tests.ts @@ -1,5 +1,3 @@ -/// - const peerByOption: Peer = new Peer({ key: 'peerKey', debug: 3 From 09832c50db44a2c8da4d4e330e0a61917fe32ec1 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sun, 25 Nov 2018 13:34:03 +0100 Subject: [PATCH 101/792] [fix] Remove trail space --- types/prompts/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index e4e2fbca80..bfb08a8bd7 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -86,7 +86,7 @@ declare namespace prompts { values: Answers, prompt: PromptObject ) => R; - + type Falsy = false | null | undefined; type ValueOrFunc = T | PrevCaller; From adace47dc209c52a74da1641206e7fbcea7023f7 Mon Sep 17 00:00:00 2001 From: Julian Strecker Date: Sun, 25 Nov 2018 13:38:13 +0100 Subject: [PATCH 102/792] [three,physijs] fix tests to fullfill travis needs. --- types/physijs/test/collisions.ts | 4 ++-- types/physijs/test/vehicle.ts | 4 ++-- types/three/test/css3d/css3d_periodictable.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/physijs/test/collisions.ts b/types/physijs/test/collisions.ts index 20493189e0..41f09e351d 100644 --- a/types/physijs/test/collisions.ts +++ b/types/physijs/test/collisions.ts @@ -90,7 +90,7 @@ spawnBox = (function() { var box_geometry = new THREE.BoxGeometry( 4, 4, 4 ), handleCollision = function( collided_with ) { - var target = this; + var target = this as any; target.collisions = 0; switch (++target.collisions) { @@ -168,4 +168,4 @@ render = function() { render_stats.update(); }; -window.onload = initScene; \ No newline at end of file +window.onload = initScene; diff --git a/types/physijs/test/vehicle.ts b/types/physijs/test/vehicle.ts index b8643de3b0..37f32279a8 100644 --- a/types/physijs/test/vehicle.ts +++ b/types/physijs/test/vehicle.ts @@ -186,11 +186,11 @@ initScene = function() { ); } - input = { + input = { power: null, direction: null, steering: 0 - }; + } as any; document.addEventListener('keydown', function( ev ) { switch ( ev.keyCode ) { case 37: // left diff --git a/types/three/test/css3d/css3d_periodictable.ts b/types/three/test/css3d/css3d_periodictable.ts index 5c8cb68614..40a29a1ea5 100644 --- a/types/three/test/css3d/css3d_periodictable.ts +++ b/types/three/test/css3d/css3d_periodictable.ts @@ -181,8 +181,8 @@ // var object = new THREE.Object3D(); - object.position.x = (table[i + 3] * 140) - 1330; - object.position.y = - (table[i + 4] * 180) + 990; + object.position.x = ((table[i + 3] as number) * 140) - 1330; + object.position.y = - ((table[i + 4] as number) * 180) + 990; targets.table.push(object); @@ -354,4 +354,4 @@ renderer.render(scene, camera); } -} \ No newline at end of file +} From 3a4659d36dc86a41af8dfeb17a6d87ad890404b8 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sun, 25 Nov 2018 14:31:37 +0100 Subject: [PATCH 103/792] Update to version 3.0.2 --- types/tabtab/index.d.ts | 152 +++++++++++++++++++++++++++------------- 1 file changed, 103 insertions(+), 49 deletions(-) diff --git a/types/tabtab/index.d.ts b/types/tabtab/index.d.ts index eba5a58c3a..05291613b2 100644 --- a/types/tabtab/index.d.ts +++ b/types/tabtab/index.d.ts @@ -1,89 +1,143 @@ -// Type definitions for tabtab 0.0.4 +// Type definitions for tabtab 3.0.2 // Project: https://github.com/mklabs/node-tabtab // Definitions by: VojtΔ›ch Habarta +// Kamontat Chantrachirathumrong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - +// TypeScript Version: 2.0 /** - * Main completion method, has support for installation and actual completion. - * @param name Name of the command to complete. - * @param cb Get called when a tab-completion command happens. + * Install option + * + * @param name is a name of the cli command + * @param completer Somethings, you want to complete another program that's where the `completer` option might come handy. */ -export declare function complete(name: string, cb: CallBack): void; +export type InstallOption = { + name: string; + completer: string; +}; /** - * Main completion method, has support for installation and actual completion. - * @param name Name of the command to complete. - * @param completer Name of the command to call on completion. - * @param cb Get called when a tab-completion command happens. + * Uninstall option + * + * @param name is a name of the cli command */ -export declare function complete(name: string, completer: string, cb: CallBack): void; +export type UninstallOption = { + name: string; +}; /** - * Simple helper function to know if the script is run in the context of a completion command. + * This type represent object (Json object) */ -export declare function isComplete(): boolean; +export type Json = { + [key: string]: string; +}; /** - * Helper to return the list of short and long options, parsed from the usual --help output of a command (cake/rake -H, vagrant, commander -h, optimist.help(), ...). + * Tabtab environment data that return from {@link parseEnv} method + * + * @param complete A Boolean indicating whether we act in "plumbing mode" or not + * @param words The Number of words in the completed line + * @param point A Number indicating cursor position + * @param line The String input line + * @param partial The String part of line preceding cursor position + * @param last The last String word of the line + * @param lastPartial The last word String of partial + * @param prev The String word preceding last */ -export declare function parseOut(str: string): { shorts: string[]; longs: string[] }; - -/** - * Same purpose as parseOut, but for parsing tasks from an help command (cake/rake -T, vagrant, etc.). - */ -export declare function parseTasks(str: string, prefix: string, reg?: RegExp | string): string[]; - -/** - * Helper to return completion output and log to standard output. - * @param values Array of values to complete against. - * @param data The data object returned by the complete callback, used mainly to filter results accordingly upon the text that is supplied by the user. - * @param prefix A prefix to add to the completion results, useful for options to add dashes (eg. - or --). - */ -export declare function log(values: string[], data: Data, prefix?: string): void; - -interface CallBack { - (error?: Error, data?: Data, text?: string): any; -} - -/** - * Holds interesting values to drive the output of the completion. - */ -interface Data { - +export type TabtabEnv = { /** - * full command being completed + * A Boolean indicating whether we act in "plumbing mode" or not */ - line: string; + complete: boolean; /** - * number of words + * The Number of words in the completed line */ words: number; /** - * cursor position + * A Number indicating cursor position */ point: number; /** - * tabing in the middle of a word: foo bar baz bar foobarrrrrrr + * The String input line + */ + line: string; + + /** + * The String part of line preceding cursor position */ partial: string; /** - * last word of the line + * The last String word of the line */ last: string; /** - * last partial of the line + * The last word String of partial */ lastPartial: string; - /** - * the previous word + * The String word preceding last */ prev: string; -} +}; + +/** + * this is a item to show when completion enable, + * + * @param name usually is a subcommand name or option name + * @param description this is a optional description of the completion + */ +export type CompleteItem = { + name: string; + description?: string; +}; + +export type CompleteItemOrString = string | CompleteItem; + +/** + * Install and enable completion on user system. + * + * @param option install option + * + */ +export function install(option: InstallOption): Promise; + +/** + * Uninstall and remove all completion on user system + * + * @param option uninstall option + */ +export function uninstall(option: UninstallOption): Promise; + +/** + * Public: Main utility to extract information from command line arguments and + * Environment variables, namely COMP args in "plumbing" mode. + * + * @param env environment (usually will be process.env) + * @returns env is a object of completion environment + * + * @example + * const env = tabtab.parseEnv(process.env); + */ +export function parseEnv(env: Json): TabtabEnv; + +/** + * Helper to normalize String and Objects when logging out. + */ +export function completionItem(item: CompleteItemOrString): CompleteItem; + +/** + * Main logging utility to pass completion items. + * This is simply an helper to log to stdout with each item separated by a new + * line. + * + * Bash needs in addition to filter out the args for the completion to work + * (zsh, fish don't need this). + * + * @param args Strings or Objects with name and description property. + */ +export function log(args: string[] | CompleteItem[] | CompleteItemOrString[]): void; From 8b982e49c565d136473bd3f794837e2374b2136a Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Sun, 25 Nov 2018 14:33:34 +0100 Subject: [PATCH 104/792] Update test define file --- types/tabtab/tabtab-tests.ts | 99 +++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 23 deletions(-) diff --git a/types/tabtab/tabtab-tests.ts b/types/tabtab/tabtab-tests.ts index e0187662ff..7f8e5b4b9c 100644 --- a/types/tabtab/tabtab-tests.ts +++ b/types/tabtab/tabtab-tests.ts @@ -1,30 +1,83 @@ - /// -import tabtab = require('tabtab'); -import child_process = require('child_process'); -import string_decoder = require('string_decoder'); +import { install, log, TabtabEnv, uninstall, parseEnv } from "tabtab"; -if (process.argv.slice(2)[0] === 'completion') { - tabtab.complete('pkgname', function(err, data) { - if (err || !data) return; - if (/^--\w?/.test(data.last)) return tabtab.log(['help', 'version'], data, '--'); - if (/^-\w?/.test(data.last)) return tabtab.log(['n', 'o', 'd', 'e'], data, '-'); - tabtab.log(['list', 'of', 'commands'], data); +const opts = require("minimist")(process.argv.slice(2), { + string: ["foo", "bar"], + boolean: ["help", "version", "loglevel"] +}); - child_process.exec('rake -H', {encoding: null}, function(err, stdout, stderr) { - if (err) return; - var decoder = new string_decoder.StringDecoder('utf8'); - var parsed = tabtab.parseOut(decoder.write(stdout)); - if (/^--\w?/.test(data.last)) return tabtab.log(parsed.longs, data, '--'); - if (/^-\w?/.test(data.last)) return tabtab.log(parsed.shorts, data, '-'); +const args = opts._; + +const completion = (env: TabtabEnv) => { + if (!env.complete) return; + + // Write your completions there + + if (env.prev === "foo") { + return log(["is", "this", "the", "real", "life"]); + } + + if (env.prev === "bar") { + return log(["is", "this", "just", "fantasy"]); + } + + if (env.prev === "--loglevel") { + return log(["error", "warn", "info", "notice", "verbose"]); + } + + return log([ + "--help", + "--version", + "--loglevel", + "foo", + "bar", + "install-completion", + "completion", + "someCommand:someCommand is some kind of command with a description", + { + name: "someOtherCommand:hey", + description: 'You must add a description for items with ":" in them' + }, + "anotherOne" + ]); +}; + +const run = (): Promise => { + const cmd = args[0]; + + // Write your CLI there + + // Here we install for the program `tabtab-test` (this file), with + // completer being the same program. Sometimes, you want to complete + // another program that's where the `completer` option might come handy. + if (cmd === "install-completion") { + return install({ + name: "tabtab-test", + completer: "tabtab-test" }); + } - child_process.exec('cake', {encoding: null}, function(err, stdout, stderr) { - if (err) return; - var decoder = new string_decoder.StringDecoder('utf8'); - var tasks = tabtab.parseTasks(decoder.write(stdout), 'cake'); - tabtab.log(tasks, data); + if (cmd === "uninstall-completion") { + // Here we uninstall for the program `tabtab-test` (this file). + return uninstall({ + name: "tabtab-test" }); - }); -} + } + + // The completion command is added automatically by tabtab when the program + // is completed. + if (cmd === "completion") { + return new Promise(res => { + const env = parseEnv(process.env); + completion(env); + res(); + }); + } + + return new Promise((_, rej) => rej()); +}; + +run().catch(e => { + console.error(e); +}); From 28cec6d7e832384d8e93596e6b723ea179d8d84f Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 25 Nov 2018 15:02:24 +0100 Subject: [PATCH 105/792] Add types for iri --- types/iri/index.d.ts | 89 +++++++++++++++++++++++++++++++++++++++++ types/iri/iri-tests.ts | 43 ++++++++++++++++++++ types/iri/tsconfig.json | 23 +++++++++++ types/iri/tslint.json | 1 + 4 files changed, 156 insertions(+) create mode 100644 types/iri/index.d.ts create mode 100644 types/iri/iri-tests.ts create mode 100644 types/iri/tsconfig.json create mode 100644 types/iri/tslint.json diff --git a/types/iri/index.d.ts b/types/iri/index.d.ts new file mode 100644 index 0000000000..93183bcfad --- /dev/null +++ b/types/iri/index.d.ts @@ -0,0 +1,89 @@ +// Type definitions for iri 1.3 +// Project: https://github.com/awwright/node-iri +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export class IRI { + /** + * The constructor takes a single argument, a URI or IRI string: + */ + constructor(iri: string); + /** + * Returns UTF-16 IRI + */ + toString(): string; + /** + * Returns the IRI without the fragment component. Useful for dereferencing URLs on a network. + */ + defrag(): IRI; + /** + * IRIs with a fragment are not absolute. + */ + isAbsolute(): boolean; + /** + * Resolves the IRI against itself, having the effect of stripping the fragment and checking that the supplied IRI is valid (absolute). + */ + toAbsolute(): IRI; + /** + * Resolves the IRI against itself, having the effect of stripping the fragment and checking that the supplied IRI is valid (absolute). + */ + authority(): string | null; + /** + * Returns the fragment component of the IRI. + */ + fragment(): string | null; + /** + * Returns the hier-part of the IRI, the hierarchial component: Everything between the scheme and query, including leading `//` for the host, if it exists. + */ + hierpart(): string; + /** + * Returns the host component of the URI, either a domain name or string-formatted IP address. Excludes port number and username/password. + */ + host(): string; + /** + * Returns the path component of the hier-part. Does not include the authority/host, query, or fragment. + */ + path(): string; + /** + * Returns the port component of the authority as a string, or `null` if there is no port. + */ + port(): string | null; + /** + * Returns the query component of the IRI including leading "?", or `null` if there is no query component. + */ + query(): string | null; + /** + * Resolve the provided URI/IRI reference against this IRI. + */ + resolveReference(ref: string | IRI): IRI; + /** + * Returns the scheme of the IRI, e.g. "https", "file", or "urn". + */ + scheme(): string | null; + /** + * Returns the username/password component of the IRI. + */ + userinfo(): string | null; + /** + * Returns a URI formatted string with only 7-bit characters. + */ + toURIString(): string; + /** + * Decodes URI-encoded UTF-8 characters and returns a unicode string (Strings in ECMAScript/JavaScript are UTF-16). + */ + toIRIString(): string; + /** + * Returns a new IRI object with URI-encoded UTF-8 characters decoded. + */ + toIRI(): IRI; +} + +/** + * Returns an iri.IRI object with UTF-8 escaped characterd decoded. + */ +export function fromURI(uri: string): IRI; + +/** + * Returns an IRI string decoded from the given URI. + */ +export function toIRIString(uri: string): string; diff --git a/types/iri/iri-tests.ts b/types/iri/iri-tests.ts new file mode 100644 index 0000000000..97a460e02c --- /dev/null +++ b/types/iri/iri-tests.ts @@ -0,0 +1,43 @@ +import { IRI, fromURI, toIRIString } from 'iri'; + +const iri = new IRI('iri'); +// $ExpectType string +iri.toString(); +// $ExpectType IRI +iri.defrag(); +// $ExpectType boolean +iri.isAbsolute(); +// $ExpectType IRI +iri.toAbsolute(); +// $ExpectType string | null +iri.authority(); +// $ExpectType string | null +iri.fragment(); +// $ExpectType string +iri.hierpart(); +// $ExpectType string +iri.host(); +// $ExpectType string +iri.path(); +// $ExpectType string | null +iri.port(); +// $ExpectType string | null +iri.query(); +// $ExpectType IRI +iri.resolveReference('ref'); +iri.resolveReference(iri); +// $ExpectType string | null +iri.scheme(); +// $ExpectType string | null +iri.userinfo(); +// $ExpectType string +iri.toURIString(); +// $ExpectType string +iri.toIRIString(); +// $ExpectType IRI +iri.toIRI(); + +// $ExpectType IRI +fromURI('u'); +// $ExpectType string +toIRIString('u'); diff --git a/types/iri/tsconfig.json b/types/iri/tsconfig.json new file mode 100644 index 0000000000..09b1e0069e --- /dev/null +++ b/types/iri/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "iri-tests.ts" + ] +} diff --git a/types/iri/tslint.json b/types/iri/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/iri/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From e80e44b0f032fc4a70d6e4d05354a6e53fb9089b Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 21 Nov 2018 01:06:14 +0100 Subject: [PATCH 106/792] Update types for @xmpp/jid --- types/xmpp__jid/index.d.ts | 84 ++++++++++++++++-------------- types/xmpp__jid/xmpp__jid-tests.ts | 55 ++++++++++--------- 2 files changed, 73 insertions(+), 66 deletions(-) diff --git a/types/xmpp__jid/index.d.ts b/types/xmpp__jid/index.d.ts index f3f5bcc485..51b19051f1 100644 --- a/types/xmpp__jid/index.d.ts +++ b/types/xmpp__jid/index.d.ts @@ -1,55 +1,63 @@ -// Type definitions for @xmpp/jid 0.0 +// Type definitions for @xmpp/jid 0.6 // Project: https://github.com/node-xmpp/node-xmpp/ // Definitions by: PJakcson +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 -export function createJID(local: string, domain: string, resource: string): JID; -export function equal(a: JID, b: JID): boolean; -export function is(a: any): boolean; +export = jid; -/** - * Created by marcneumann on 17.02.17. - */ -export class JID { - local: string; - domain: string; - resource: string; +declare function jid(address: string): jid.JID; +declare function jid(local: string | undefined, domain: string, resource?: string): jid.JID; - constructor(local: string, domain?: string, resource?: string); +declare namespace jid { + function jid(address: string): JID; + function jid(local: string | undefined, domain: string, resource?: string): JID; - parseJID(jid: string): void; + function createJID(local: string | undefined, domain: string, resource?: string): JID; + function equal(a: JID, b: JID): boolean; + function detectEscape(local?: string): boolean; + function escapeLocal(local: string): string; + function unescapeLocal(local: string): string; + function parse(s: string): JID; - toString(unescape?: any): string; + class JID { + local: string; + domain: string; + resource: string; - /** - * Convenience method to distinguish users - */ - bare(): JID; + constructor(local: string | undefined, domain: string, resource?: string); - /** - * Comparison function - */ - equals(other: JID): boolean; + toString(unescape?: boolean): string; - /** - * http://xmpp.org/rfcs/rfc6122.html#addressing-localpart - */ - setLocal(local: string, escape?: any): void; + /** + * Convenience method to distinguish users + */ + bare(): JID; - getLocal(unescape?: any): string; + /** + * Comparison function + */ + equals(other: JID): boolean; - /** - * http://xmpp.org/rfcs/rfc6122.html#addressing-domain - */ - setDomain(value: string): void; + /** + * http://xmpp.org/rfcs/rfc6122.html#addressing-localpart + */ + setLocal(local: string, escape?: boolean): void; - getDomain(): string; + getLocal(unescape?: boolean): string; - /** - * http://xmpp.org/rfcs/rfc6122.html#addressing-resourcepart - */ - setResource(value: string): void; + /** + * http://xmpp.org/rfcs/rfc6122.html#addressing-domain + */ + setDomain(value: string): void; - getResource(): string; + getDomain(): string; + + /** + * http://xmpp.org/rfcs/rfc6122.html#addressing-resourcepart + */ + setResource(value: string): void; + + getResource(): string; + } } diff --git a/types/xmpp__jid/xmpp__jid-tests.ts b/types/xmpp__jid/xmpp__jid-tests.ts index d26ede9a15..4a79d5849f 100644 --- a/types/xmpp__jid/xmpp__jid-tests.ts +++ b/types/xmpp__jid/xmpp__jid-tests.ts @@ -1,40 +1,39 @@ -import { JID } from '@xmpp/jid'; +import jid = require('@xmpp/jid'); -/* - * All return an instance of JID.JID, the new operator is optional. - */ -let addr = new JID('alice@wonderland.net/rabbithole'); // OK -addr = new JID('alice', 'wonderland.net', 'rabbithole'); // BEST; see section on escaping below +let addr: jid.JID; +let str: string; +let bool: boolean; + +addr = jid('alice@wonderland.net/rabbithole'); +addr = jid('alice', 'wonderland.net', 'rabbithole'); -/* - * local - */ addr.local = 'alice'; -addr.local; // alice -// same as +str = addr.local; addr.setLocal('alice'); -addr.getLocal(); // alice +addr.setLocal('alice', true); +str = addr.getLocal(); -/* - * domain - */ addr.domain = 'wonderland.net'; -addr.domain; // wonderland.net -// same as +str = addr.domain; addr.setDomain('wonderland.net'); -addr.getDomain(); // wonderland.net +str = addr.getDomain(); -/* - * resource - */ addr.resource = 'rabbithole'; -addr.resource; // rabbithole -// same as +str = addr.resource; addr.setResource('rabbithole'); -addr.getResource(); // rabbithole +str = addr.getResource(); -addr.toString(); // alice@wonderland.net/rabbithole -addr.bare(); // returns a JID without resource +str = addr.toString(); +str = addr.toString(true); +addr = addr.bare(); -const some_jid = new JID('is', 'a', 'test'); -addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise +bool = addr.equals(addr); + +bool = jid.equal(addr, addr); + +addr = jid.createJID('my', 'homies'); +bool = jid.equal(addr, addr); +bool = jid.detectEscape('homies'); +str = jid.escapeLocal('homies'); +str = jid.unescapeLocal('homies'); +addr = jid.parse('homies'); From 43a1c3ef84dbfbe230c5386bb7a5d395d0562774 Mon Sep 17 00:00:00 2001 From: erikma Date: Sun, 25 Nov 2018 12:29:13 -0800 Subject: [PATCH 107/792] Update pigpio types to include changes up to version 1.2.0 --- types/pigpio/index.d.ts | 28 ++++++++++++++++++++++++++-- types/pigpio/pigpio-tests.ts | 9 +++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/types/pigpio/index.d.ts b/types/pigpio/index.d.ts index 79d0ebe0f9..1bc901f084 100644 --- a/types/pigpio/index.d.ts +++ b/types/pigpio/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for pigpio 0.4 +// Type definitions for pigpio 1.2 // Project: https://github.com/fivdi/pigpio -// Definitions by: ManerFan +// Definitions by: ManerFan and erikma // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -424,3 +424,27 @@ export function configureClock(microseconds: number, peripheral: number): void; * @param port an unsigned integer specifying the pigpio socket port number */ export function configureSocketPort(port: number): void; + +/** + * Returns the Raspberry Pi hardware revision as an unsigned integer. Returns 0 + * if the hardware revision can not be determined. + */ +export function hardwareRevision(): number; + +/** + * Gets the current unsigned 32-bit integer value of the number of microseconds + * since system boot. This value wraps around the 32-bit space in just over an hour. + * Use tickDiff() to get the difference between two tick values, to + * ensure the correct JavaScript operations are used to account for the possibility + * of overflow. + */ +export function getTick(): number; + +/** + * Returns the difference in microseconds between the end and start tick counts. + * The tick counts can be retrieved using getTick(), or may be passed + * in a GPIO event callback. + * @param startTick The start of the measured interval. An unsigned integer tick value. + * @param endTick The end of the measured interval. An unsigned integer tick value. + */ +export function tickDiff(startTick: number, endTick: number): number; diff --git a/types/pigpio/pigpio-tests.ts b/types/pigpio/pigpio-tests.ts index 90e7d4485d..f756058b03 100644 --- a/types/pigpio/pigpio-tests.ts +++ b/types/pigpio/pigpio-tests.ts @@ -880,6 +880,15 @@ import * as assert from 'assert'; }, 2000); })(); +(function tickAndTickDiff(): void { + const startTick: number = pigpio.getTick(); + setTimeout(() => { + const endTick: number = pigpio.getTick(); + const diff: number = pigpio.tickDiff(startTick, endTick); + assert.ok(diff > 0, 'expected tick count to increase across a timer call'); + }, 50); +})(); + (function gpio_glitch_filter(): void { const Gpio = pigpio.Gpio; const input = new Gpio(7, { From 3465be17ba8e9ec2628e3bfae2d5b67cdd1955ac Mon Sep 17 00:00:00 2001 From: erikma Date: Sun, 25 Nov 2018 12:35:43 -0800 Subject: [PATCH 108/792] fix lint issue --- types/pigpio/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/pigpio/index.d.ts b/types/pigpio/index.d.ts index 1bc901f084..8eaa6491bb 100644 --- a/types/pigpio/index.d.ts +++ b/types/pigpio/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for pigpio 1.2 // Project: https://github.com/fivdi/pigpio -// Definitions by: ManerFan and erikma +// Definitions by: ManerFan , erikma // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From 7416fd03c44b5a4d9e9ce6eb5bd4418d754adac0 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Sun, 25 Nov 2018 21:42:31 +0100 Subject: [PATCH 109/792] Add encrypt and decrypt to Pubnub types --- types/pubnub/index.d.ts | 22 +++++++++++++++++++++- types/pubnub/pubnub-tests.ts | 12 ++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 8337acfbe4..1fc38edabf 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for pubnub 4.0 // Project: https://github.com/pubnub/javascript -// Definitions by: bitbankinc , rollymaduk , vitosamson +// Definitions by: bitbankinc , rollymaduk , vitosamson , FlorianDr // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration @@ -88,6 +88,18 @@ declare class Pubnub { setState( params: Pubnub.SetStateParameters ): Promise; + + encrypt( + data: string, + customCipherKey?: string, + options?: Pubnub.CryptoParameters, + ): object | string | null; + + decrypt( + data: object, + customCipherKey?: string, + options?: Pubnub.CryptoParameters + ): object | string | null; } declare namespace Pubnub { @@ -296,6 +308,14 @@ declare namespace Pubnub { }; } + // encrypt + interface CryptoParameters { + encryptKey?: boolean; + keyEncoding?: string; + keyLength?: number; + mode?: string; + } + interface Categories { PNNetworkUpCategory: string; PNNetworkDownCategory: string; diff --git a/types/pubnub/pubnub-tests.ts b/types/pubnub/pubnub-tests.ts index 1d8b2bb1ca..50660bd942 100644 --- a/types/pubnub/pubnub-tests.ts +++ b/types/pubnub/pubnub-tests.ts @@ -86,3 +86,15 @@ pubnub.setState({ channels: [] }, (status, res) => { pubnub.setState({ channels: [] }).then(res => { console.log(res.state); }); + +const cryptoOptions = { + encryptKey: true, + keyEncoding: 'utf8', + keyLength: 256, + mode: 'cbc' +}; +const mySecret = { + message: 'Hi!', +}; +pubnub.decrypt(mySecret, undefined, cryptoOptions); +pubnub.encrypt('egrah5rwgrehwqh5eh3hwfwef', undefined, cryptoOptions); From 147d828b80b191986af9e796d635e0cef3fdae14 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Sun, 25 Nov 2018 21:44:14 +0100 Subject: [PATCH 110/792] Add comment for decrypt parameters --- types/pubnub/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 1fc38edabf..0b5f75901c 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -308,7 +308,7 @@ declare namespace Pubnub { }; } - // encrypt + // encrypt & decrypt interface CryptoParameters { encryptKey?: boolean; keyEncoding?: string; From 44ef75a9066b67df3e76d93f12bff05a408e7137 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Sun, 25 Nov 2018 21:58:23 +0100 Subject: [PATCH 111/792] Add version note under header --- types/pubnub/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 0b5f75901c..7e148bc4c4 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: bitbankinc , rollymaduk , vitosamson , FlorianDr // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration +// TypeScript Version: 2.2 declare class Pubnub { constructor(config: Pubnub.PubnubConfig); From 620ad409303126f5066dc1dda42ec23ce0bf2f4f Mon Sep 17 00:00:00 2001 From: Karol Samborski Date: Sun, 25 Nov 2018 22:50:42 +0100 Subject: [PATCH 112/792] Type definitions for multiSamlStrategy --- types/passport-saml/index.d.ts | 1 + types/passport-saml/passport-saml-tests.ts | 25 ++++++++++++++++++++++ types/passport-saml/tsconfig.json | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/types/passport-saml/index.d.ts b/types/passport-saml/index.d.ts index cc2faafe5c..9338b88deb 100644 --- a/types/passport-saml/index.d.ts +++ b/types/passport-saml/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/bergie/passport-saml // Definitions by: Chris Barth // Damian Assennato +// Karol Samborski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 diff --git a/types/passport-saml/passport-saml-tests.ts b/types/passport-saml/passport-saml-tests.ts index 615c1b7320..b22421fe81 100644 --- a/types/passport-saml/passport-saml-tests.ts +++ b/types/passport-saml/passport-saml-tests.ts @@ -1,6 +1,7 @@ import express = require('express'); import passport = require('passport'); import SamlStrategy = require('passport-saml'); +import MultiSamlStrategy = require('passport-saml/multiSamlStrategy'); import fs = require('fs'); const samlStrategy = new SamlStrategy.Strategy( @@ -33,3 +34,27 @@ passport.use(samlStrategy); passport.authenticate('samlCustomName', {failureRedirect: '/', failureFlash: true}); const metadata = samlStrategy.generateServiceProviderMetadata("decryptionCert"); + +const multiSamlStrategy = new MultiSamlStrategy.MultiSamlStrategy( + { + name: 'samlCustomName', + path: '/login/callback', + entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php', + issuer: 'passport-saml', + getSamlOptions(req: express.Request, callback: (err: Error | null, samlOptions: SamlStrategy.SamlConfig) => void) { + callback(null, { + name: 'samlCustomName', + path: '/login/callback2', + entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php', + issuer: 'passport-saml', + }); + } + }, + (profile: {}, done: (err: Error | null, user: {}, info?: {}) => void) => { + const user = {}; + done(null, user); + } +); + +passport.use(multiSamlStrategy); +passport.authenticate('samlCustomName', {failureRedirect: '/', failureFlash: true}); diff --git a/types/passport-saml/tsconfig.json b/types/passport-saml/tsconfig.json index 0809dbbaf7..39283fa663 100644 --- a/types/passport-saml/tsconfig.json +++ b/types/passport-saml/tsconfig.json @@ -18,6 +18,7 @@ }, "files": [ "index.d.ts", + "multiSamlStrategy.d.ts", "passport-saml-tests.ts" ] -} \ No newline at end of file +} From 58db065b6e539e777e8f0b9726fd187297651621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Thu, 22 Nov 2018 22:54:38 +0100 Subject: [PATCH 113/792] Add types for deprecate --- types/deprecate/deprecate-tests.ts | 9 ++++++++ types/deprecate/index.d.ts | 33 ++++++++++++++++++++++++++++++ types/deprecate/tsconfig.json | 23 +++++++++++++++++++++ types/deprecate/tslint.json | 3 +++ 4 files changed, 68 insertions(+) create mode 100644 types/deprecate/deprecate-tests.ts create mode 100644 types/deprecate/index.d.ts create mode 100644 types/deprecate/tsconfig.json create mode 100644 types/deprecate/tslint.json diff --git a/types/deprecate/deprecate-tests.ts b/types/deprecate/deprecate-tests.ts new file mode 100644 index 0000000000..3df2257c40 --- /dev/null +++ b/types/deprecate/deprecate-tests.ts @@ -0,0 +1,9 @@ +import deprecate = require('deprecate'); + +deprecate('someMethod'); +deprecate('someMethod', 'This is deprecated'); +deprecate('someMethod', 'This is deprecated', 'foo', 'bar'); + +deprecate.color = '\x1b[31;1m'; +deprecate.silence = true; +deprecate.stream = process.stderr; diff --git a/types/deprecate/index.d.ts b/types/deprecate/index.d.ts new file mode 100644 index 0000000000..a053721ff5 --- /dev/null +++ b/types/deprecate/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for deprecate 1.1 +// Project: https://github.com/brianc/node-deprecate +// Definitions by: Toilal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +declare namespace deprecate { + /** + * Set to false to not output a color. Defaults to '\x1b[31;1m' which is red. + */ + let color: string; + + /** + * Set to false to do nothing at all when the deprecate method is called. Useful in tests of the library you're deprecating things within. + */ + let silence: boolean; + + /** + * The stream to which output is written. Defaults to process.stderr + */ + let stream: NodeJS.WriteStream; +} + +/** + * Call deprecate within a function you are deprecating. + * + * It will spit out all the messages to the console the first time and only the first time the method is called. + */ +declare function deprecate(methodName: string, ...message: string[]): void; + +export = deprecate; diff --git a/types/deprecate/tsconfig.json b/types/deprecate/tsconfig.json new file mode 100644 index 0000000000..75acd6cda6 --- /dev/null +++ b/types/deprecate/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "deprecate-tests.ts" + ] +} diff --git a/types/deprecate/tslint.json b/types/deprecate/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/deprecate/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From cc95a58bf19a53762240bcdabf1ac18c040a5904 Mon Sep 17 00:00:00 2001 From: Karol Samborski Date: Mon, 26 Nov 2018 07:13:25 +0100 Subject: [PATCH 114/792] Missing file --- types/passport-saml/multiSamlStrategy.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 types/passport-saml/multiSamlStrategy.d.ts diff --git a/types/passport-saml/multiSamlStrategy.d.ts b/types/passport-saml/multiSamlStrategy.d.ts new file mode 100644 index 0000000000..405c7264dc --- /dev/null +++ b/types/passport-saml/multiSamlStrategy.d.ts @@ -0,0 +1,10 @@ +import express = require('express'); +import { Strategy, SamlConfig, VerifyWithRequest, VerifyWithoutRequest } from './index'; + +export interface MultiSamlConfig extends SamlConfig { + getSamlOptions(req: express.Request, callback: (err: Error | null, samlOptions: SamlConfig) => void): void; +} + +export class MultiSamlStrategy extends Strategy { + constructor(config: MultiSamlConfig, verify: VerifyWithRequest | VerifyWithoutRequest); +} From 59bfd27bf6b5d17c6d9485d8d08b0db3e42add13 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 26 Nov 2018 19:09:42 +0900 Subject: [PATCH 115/792] Add support to the `css` prop from babel-plugin-styled-components --- types/styled-components/index.d.ts | 20 +++++++ types/styled-components/test/index.tsx | 74 +++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 6 deletions(-) diff --git a/types/styled-components/index.d.ts b/types/styled-components/index.d.ts index a842c94c63..ee64b37772 100644 --- a/types/styled-components/index.d.ts +++ b/types/styled-components/index.d.ts @@ -436,4 +436,24 @@ export class StyleSheetManager extends React.Component< StyleSheetManagerProps > {} +export type CSSIntrinsicAttributeType = + | string + | CSSObject + | FlattenSimpleInterpolation + // Sad, but because this is global, there is no way to override it with the ThemedStyledComponentsModule + // Only augmenting DefaultTheme will work for inline css prop + | FlattenInterpolation>>; + export default styled; + +declare module "react" { + interface Attributes { + // NOTE: unlike the plain javascript version, it is not possible to get access + // to the element's own attributes inside function interpolations. + // Only theme will be accessible, and only with the DefaultTheme due to the global + // nature of this declaration. + // If you are writing this inline you already have access to all the attributes anyway, + // no need for the extra indirection. + css?: import(".").CSSIntrinsicAttributeType; // tslint:disable-line whitespace + } +} diff --git a/types/styled-components/test/index.tsx b/types/styled-components/test/index.tsx index e435d90011..c152ffd66e 100644 --- a/types/styled-components/test/index.tsx +++ b/types/styled-components/test/index.tsx @@ -172,7 +172,6 @@ const styledButton = styled.button` const name = "hey"; const ThemedMyButton = withTheme(MyButton); - ; /** @@ -290,7 +289,6 @@ const ObjectStylesBox = styled.div` fontSize: 2 }}; `; - ; /** @@ -322,7 +320,6 @@ const AttrsWithOnlyNewProps = styled.h2.attrs({ as: "h1" })` `; const AttrsInputExtra = styled(AttrsInput).attrs({ autoComplete: "off" })``; - ; /** @@ -419,10 +416,8 @@ const Component = (props: WithThemeProps) => ( ); const ComponentWithTheme = withTheme(Component); - ; // ok ; // ok - {theme => }; /** @@ -610,7 +605,6 @@ const divFnRef = (ref: HTMLDivElement | null) => { const divRef = React.createRef(); const StyledDiv = styled.div``; - ; ; ; // $ExpectError @@ -771,3 +765,71 @@ async function themeAugmentation() { ); } + +// NOTE: this is needed for some tests inside cssProp, +// but actually running this module augmentation will cause +// tests elsewhere to break, and there is no way to contain it. +// Uncomment out as needed to run tests. + +// declare module "styled-components" { +// interface DefaultTheme { +// background: string; +// } +// } + +function cssProp() { + function Custom(props: React.ComponentPropsWithoutRef<"div">) { + return
; + } + + return ( + <> +
+
+
+
+
"blue"}; + `} + /> +
{ + // This requires the DefaultTheme augmentation + // // $ExpectType string + // props.theme.background; + return props.theme.background; + }}; + `} + /> + + + + + "blue"}; + `} + /> + { + // This requires the DefaultTheme augmentation + // // $ExpectType string + // props.theme.background; + return props.theme.background; + }}; + `} + /> + + ); +} From 3fc77b020c5482986330cc606cddc0981052e784 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 26 Nov 2018 19:22:27 +0900 Subject: [PATCH 116/792] Fix the types in rebass__grid --- types/rebass__grid/index.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/types/rebass__grid/index.d.ts b/types/rebass__grid/index.d.ts index 079506e631..f49d43a6c6 100644 --- a/types/rebass__grid/index.d.ts +++ b/types/rebass__grid/index.d.ts @@ -10,7 +10,7 @@ export type Omit = Pick; import { ComponentType } from "react"; -import { StyledComponent, Interpolation } from "styled-components"; +import { StyledComponent, CSSIntrinsicAttributeType } from "styled-components"; export type ResponsiveProp = number | string | Array; @@ -34,7 +34,10 @@ export interface CommonProps { px?: ResponsiveProp; py?: ResponsiveProp; theme?: any; - css?: Interpolation; + /** + * NOTE: this is not compatible with the styled-components babel plugin anymore + */ + css?: CSSIntrinsicAttributeType; } export interface BoxProps From d3c9c35fc625641c4c95d54eef25a8c0d84e71a7 Mon Sep 17 00:00:00 2001 From: Mihkel Sokk Date: Mon, 26 Nov 2018 14:26:50 +0200 Subject: [PATCH 117/792] [ejs] renderFile returns Promise without callback, fixes #28934 --- types/ejs/ejs-tests.ts | 3 +++ types/ejs/index.d.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/types/ejs/ejs-tests.ts b/types/ejs/ejs-tests.ts index 8a0b2404d7..881a3fe103 100644 --- a/types/ejs/ejs-tests.ts +++ b/types/ejs/ejs-tests.ts @@ -29,6 +29,9 @@ result = ejs.render(template, data, options); result = ejs.renderFile(fileName, SimpleCallback); result = ejs.renderFile(fileName, data, SimpleCallback); result = ejs.renderFile(fileName, data, options, SimpleCallback); +asyncResult = ejs.renderFile(fileName); +asyncResult = ejs.renderFile(fileName, data); +asyncResult = ejs.renderFile(fileName, data, options); ejsFunction = ejs.compile(''); ejsFunction = ejs.compile(read(fileName, "utf8")); diff --git a/types/ejs/index.d.ts b/types/ejs/index.d.ts index 73eb716e23..fc578cffff 100644 --- a/types/ejs/index.d.ts +++ b/types/ejs/index.d.ts @@ -54,6 +54,8 @@ export type RenderFileCallback = (err: Error, str?: string) => T; export function renderFile(path: string, cb: RenderFileCallback): T; export function renderFile(path: string, data: Data, cb: RenderFileCallback): T; export function renderFile(path: string, data: Data, opts: Options, cb: RenderFileCallback): T; +// tslint:disable-next-line no-unnecessary-generics +export function renderFile(path: string, data?: Data, opts?: Options): Promise; /** * Clear intermediate JavaScript cache. Calls {@link Cache#reset}. From a941c86b563f56f65e6038c6f35debe28fba2514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C4=8D=C3=ADk?= Date: Mon, 26 Nov 2018 14:57:35 +0100 Subject: [PATCH 118/792] Added RN Image width and height props --- types/react-native/index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 2386fc71c2..112abe79a9 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -3629,6 +3629,12 @@ interface ImagePropsAndroid { * Duration of fade in animation. */ fadeDuration?: number; + + /** + * Required sizes if using native image resources on Android + */ + width?: number; + height?: number; } /** From 18d0d101f1c388ce03b6f815337e195fd92fd1d8 Mon Sep 17 00:00:00 2001 From: Kai Dorschner Date: Mon, 26 Nov 2018 15:05:20 +0100 Subject: [PATCH 119/792] Add missing inputIconPosition to type definition. see http://airbnb.io/react-dates/?selectedKind=DRP%20-%20Input%20Props&selectedStory=with%20show%20calendar%20icon%20after%20input&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel --- types/react-dates/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/react-dates/index.d.ts b/types/react-dates/index.d.ts index 05058b2ca9..9e96538f7d 100644 --- a/types/react-dates/index.d.ts +++ b/types/react-dates/index.d.ts @@ -55,6 +55,7 @@ declare namespace ReactDates { screenReaderInputMessage?: string, showClearDates?: boolean, showDefaultInputIcon?: boolean, + inputIconPosition?: IconPositionShape, customInputIcon?: string | JSX.Element, customArrowIcon?: string | JSX.Element, customCloseIcon?: string | JSX.Element, From ce71e7bb557834aa38e36ed35903d80cb35bb4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ba=C4=8D=C3=ADk?= Date: Mon, 26 Nov 2018 15:40:11 +0100 Subject: [PATCH 120/792] Removed whitespace --- types/react-native/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 112abe79a9..15423558e4 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -3629,7 +3629,7 @@ interface ImagePropsAndroid { * Duration of fade in animation. */ fadeDuration?: number; - + /** * Required sizes if using native image resources on Android */ From f26696ad1980206be1efc54f1f407b067801a5a7 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Mon, 26 Nov 2018 15:32:07 +0100 Subject: [PATCH 121/792] add typings for open-apifactory --- types/openapi-factory/index.d.ts | 49 +++++++++++++++++++ .../openapi-factory/openapi-factory-tests.ts | 25 ++++++++++ types/openapi-factory/tsconfig.json | 23 +++++++++ types/openapi-factory/tslint.json | 3 ++ 4 files changed, 100 insertions(+) create mode 100644 types/openapi-factory/index.d.ts create mode 100644 types/openapi-factory/openapi-factory-tests.ts create mode 100644 types/openapi-factory/tsconfig.json create mode 100644 types/openapi-factory/tslint.json diff --git a/types/openapi-factory/index.d.ts b/types/openapi-factory/index.d.ts new file mode 100644 index 0000000000..6cb22f7194 --- /dev/null +++ b/types/openapi-factory/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for openapi-factory 4.2 +// Project: https://github.com/wparad/openapi-factory.js +// Definitions by: Daan Boerlage +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare namespace OpenApi { + interface OpenApiOptions { + requestMiddleware?: () => any; + responseMiddleware?: () => any; + errorMiddleware?: () => any; + } +} + +declare class OpenApi { + constructor(options: OpenApi.OpenApiOptions, overrideLogger?: () => void); + + setAuthorizer(authorizerFunc: (req?: any) => any): void; + onEvent(onEventFunc: (req?: any) => any): void; + onSchedule(onScheduleFunc: (req?: any) => any): void; + + head(route: string, p0: (req?: any) => any): void; + head(route: string, p0: object, p1: (req?: any) => any): void; + + get(route: string, p0: (req?: any) => any): void; + get(route: string, p0: object, p1: (req?: any) => any): void; + + post(route: string, p0: (req?: any) => any): void; + post(route: string, p0: object, p1: (req?: any) => any): void; + + put(route: string, p0: (req?: any) => any): void; + put(route: string, p0: object, p1: (req?: any) => any): void; + + patch(route: string, p0: (req?: any) => any): void; + patch(route: string, p0: object, p1: (req?: any) => any): void; + + delete(route: string, p0: (req?: any) => any): void; + delete(route: string, p0: object, p1: (req?: any) => any): void; + + options(route: string, p0: (req?: any) => any): void; + options(route: string, p0: object, p1: (req?: any) => any): void; + + any(route: string, p0: (req?: any) => any): void; + any(route: string, p0: object, p1: (req?: any) => any): void; + + handler(event: object, context: object): Promise; +} + +export = OpenApi; diff --git a/types/openapi-factory/openapi-factory-tests.ts b/types/openapi-factory/openapi-factory-tests.ts new file mode 100644 index 0000000000..13e1e0e7cc --- /dev/null +++ b/types/openapi-factory/openapi-factory-tests.ts @@ -0,0 +1,25 @@ +import * as OpenApiFactory from 'openapi-factory'; + +const api = new OpenApiFactory({}); + +api.setAuthorizer((req: any) => req); +api.onEvent((req: any) => req); +api.onSchedule((req: any) => req); + +api.head('/v1/test', () => 'success'); +api.get('/v1/test', () => 'success'); +api.post('/v1/test', () => 'success'); +api.put('/v1/test', () => 'success'); +api.patch('/v1/test', () => 'success'); +api.delete('/v1/test', () => 'success'); +api.options('/v1/test', () => 'success'); +api.any('/v1/test2', () => 'success'); + +api.head('/v2/test', {test: true}, () => 'success'); +api.get('/v2/test', {test: true}, () => 'success'); +api.post('/v2/test', {test: true}, () => 'success'); +api.put('/v2/test', {test: true}, () => 'success'); +api.patch('/v2/test', {test: true}, () => 'success'); +api.delete('/v2/test', {test: true}, () => 'success'); +api.options('/v2/test', {test: true}, () => 'success'); +api.any('/v2/test2', {test: true}, () => 'success'); diff --git a/types/openapi-factory/tsconfig.json b/types/openapi-factory/tsconfig.json new file mode 100644 index 0000000000..e8528e8e84 --- /dev/null +++ b/types/openapi-factory/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "openapi-factory-tests.ts" + ] +} diff --git a/types/openapi-factory/tslint.json b/types/openapi-factory/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/openapi-factory/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From f675d110aae80c33bdc289624c85052a2a1dc858 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Mon, 26 Nov 2018 16:16:36 +0100 Subject: [PATCH 122/792] Change crypto payload to any --- types/pubnub/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 7e148bc4c4..257ca3cd44 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -94,13 +94,13 @@ declare class Pubnub { data: string, customCipherKey?: string, options?: Pubnub.CryptoParameters, - ): object | string | null; + ): any; decrypt( data: object, customCipherKey?: string, options?: Pubnub.CryptoParameters - ): object | string | null; + ): any; } declare namespace Pubnub { From 7bba952b5759fceb1b6307c807482380600047b5 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Mon, 26 Nov 2018 18:29:53 +0100 Subject: [PATCH 123/792] [openapi-factory] fix http methods param typings --- types/openapi-factory/index.d.ts | 52 +++++++++++-------- .../openapi-factory/openapi-factory-tests.ts | 36 +++++++------ 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/types/openapi-factory/index.d.ts b/types/openapi-factory/index.d.ts index 6cb22f7194..e41958e6df 100644 --- a/types/openapi-factory/index.d.ts +++ b/types/openapi-factory/index.d.ts @@ -5,43 +5,53 @@ // TypeScript Version: 2.2 declare namespace OpenApi { - interface OpenApiOptions { + interface ApiOptions { requestMiddleware?: () => any; responseMiddleware?: () => any; errorMiddleware?: () => any; } + + interface HttpMethodOptions { + rawBody?: boolean; + } + + interface HttpResponse { + statusCode?: number; + headers?: object; + body?: (object | string); + } } declare class OpenApi { - constructor(options: OpenApi.OpenApiOptions, overrideLogger?: () => void); + constructor(options: OpenApi.ApiOptions, overrideLogger?: () => void); - setAuthorizer(authorizerFunc: (req?: any) => any): void; - onEvent(onEventFunc: (req?: any) => any): void; - onSchedule(onScheduleFunc: (req?: any) => any): void; + setAuthorizer(authorizerFunc: (req?: any) => Promise): void; + onEvent(onEventFunc: (req?: any) => Promise): void; + onSchedule(onScheduleFunc: (req?: any) => Promise): void; - head(route: string, p0: (req?: any) => any): void; - head(route: string, p0: object, p1: (req?: any) => any): void; + head(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + head(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: any) => any): void; - get(route: string, p0: (req?: any) => any): void; - get(route: string, p0: object, p1: (req?: any) => any): void; + get(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + get(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; - post(route: string, p0: (req?: any) => any): void; - post(route: string, p0: object, p1: (req?: any) => any): void; + post(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + post(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; - put(route: string, p0: (req?: any) => any): void; - put(route: string, p0: object, p1: (req?: any) => any): void; + put(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + put(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; - patch(route: string, p0: (req?: any) => any): void; - patch(route: string, p0: object, p1: (req?: any) => any): void; + patch(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + patch(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; - delete(route: string, p0: (req?: any) => any): void; - delete(route: string, p0: object, p1: (req?: any) => any): void; + delete(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + delete(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; - options(route: string, p0: (req?: any) => any): void; - options(route: string, p0: object, p1: (req?: any) => any): void; + options(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + options(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; - any(route: string, p0: (req?: any) => any): void; - any(route: string, p0: object, p1: (req?: any) => any): void; + any(route: string, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; + any(route: string, options: OpenApi.HttpMethodOptions, handler: (req?: object) => (OpenApi.HttpResponse | Promise)): void; handler(event: object, context: object): Promise; } diff --git a/types/openapi-factory/openapi-factory-tests.ts b/types/openapi-factory/openapi-factory-tests.ts index 13e1e0e7cc..ad24a5021d 100644 --- a/types/openapi-factory/openapi-factory-tests.ts +++ b/types/openapi-factory/openapi-factory-tests.ts @@ -6,20 +6,24 @@ api.setAuthorizer((req: any) => req); api.onEvent((req: any) => req); api.onSchedule((req: any) => req); -api.head('/v1/test', () => 'success'); -api.get('/v1/test', () => 'success'); -api.post('/v1/test', () => 'success'); -api.put('/v1/test', () => 'success'); -api.patch('/v1/test', () => 'success'); -api.delete('/v1/test', () => 'success'); -api.options('/v1/test', () => 'success'); -api.any('/v1/test2', () => 'success'); +const testReponse = { + statusCode: 200 +}; -api.head('/v2/test', {test: true}, () => 'success'); -api.get('/v2/test', {test: true}, () => 'success'); -api.post('/v2/test', {test: true}, () => 'success'); -api.put('/v2/test', {test: true}, () => 'success'); -api.patch('/v2/test', {test: true}, () => 'success'); -api.delete('/v2/test', {test: true}, () => 'success'); -api.options('/v2/test', {test: true}, () => 'success'); -api.any('/v2/test2', {test: true}, () => 'success'); +api.head('/v1/test', () => testReponse); +api.get('/v1/test', () => testReponse); +api.post('/v1/test', () => testReponse); +api.put('/v1/test', () => testReponse); +api.patch('/v1/test', () => testReponse); +api.delete('/v1/test', () => testReponse); +api.options('/v1/test', () => testReponse); +api.any('/v1/test2', () => testReponse); + +api.head('/v2/test', { rawBody: true }, () => testReponse); +api.get('/v2/test', { rawBody: true }, () => testReponse); +api.post('/v2/test', { rawBody: true }, () => testReponse); +api.put('/v2/test', { rawBody: true }, () => testReponse); +api.patch('/v2/test', { rawBody: true }, () => testReponse); +api.delete('/v2/test', { rawBody: true }, () => testReponse); +api.options('/v2/test', { rawBody: true }, () => testReponse); +api.any('/v2/test2', { rawBody: true }, () => testReponse); From 70d843fd2fd329ad7e3ab49364cfa5bf437643cb Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Mon, 26 Nov 2018 19:50:25 +0100 Subject: [PATCH 124/792] Add Typings for microservice-utilities --- types/microservice-utilities/index.d.ts | 84 +++++++++++++++++++ .../microservice-utilities-tests.ts | 13 +++ types/microservice-utilities/tsconfig.json | 23 +++++ types/microservice-utilities/tslint.json | 3 + 4 files changed, 123 insertions(+) create mode 100644 types/microservice-utilities/index.d.ts create mode 100644 types/microservice-utilities/microservice-utilities-tests.ts create mode 100644 types/microservice-utilities/tsconfig.json create mode 100644 types/microservice-utilities/tslint.json diff --git a/types/microservice-utilities/index.d.ts b/types/microservice-utilities/index.d.ts new file mode 100644 index 0000000000..e8ccb9284e --- /dev/null +++ b/types/microservice-utilities/index.d.ts @@ -0,0 +1,84 @@ +// Type definitions for microservice-utilities 0.1 +// Project: https://github.com/Cimpress-MCP/microservice-utilities.js +// Definitions by: Daan Boerlage +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/** + * Authorizer + */ + +export interface AuthorizerConfiguration { + jwkKeyListUrl: string; + authorizerContextResolver?: string; +} + +export interface AuthorizerPolicy { + principalId: string; + policyDocument: object; +} + +export class Authorizer { + constructor(logFunction: (msg: any) => void, configuration: AuthorizerConfiguration); + getPolicy(request: object): Promise; +} + +/** + * PlatformClient + */ + +export interface PlatformClientConfiguration { + client: object; +} + +export interface PlatformClientResponse { + data?: any; + status: number; + statusText: string; + headers: any; + config: object; + request?: any; +} + +export class PlatformClient { + constructor(logFunction: (msg: any) => void, tokenResolverFunction?: Promise<() => string>, configuration?: PlatformClientConfiguration) + get(url: string, headers?: object, type?: string): Promise; + post(url: string, data: object, headers?: object): Promise; + put(url: string, data: object, headers?: object): Promise; + patch(url: string, data: object, headers?: object): Promise; + delete(url: string, headers?: object): Promise; + head(url: string, headers?: object): Promise; + options(url: string, headers?: object): Promise; +} + +/** + * RequestLogger + */ + +export interface RequestLoggerConfiguration { + logFunction?: (msg: any) => void; + extendErrorObjects?: boolean; + jsonSpace?: number; +} + +export class RequestLogger { + constructor(configuration?: RequestLoggerConfiguration); + log(msg: any): void; +} + +/** + * ServiceTokenProvider + */ + +export interface ServiceTokenProviderConfiguration { + clientId: string; + encryptedClientSecret: string; + audience: string; + tokenEndpoint: string; +} + +export class ServiceTokenProvider { + constructor(httpClient: object, kmsClient: object, configuration?: ServiceTokenProviderConfiguration); + getToken(): Promise; + getTokenWithoutCache(): Promise; +} diff --git a/types/microservice-utilities/microservice-utilities-tests.ts b/types/microservice-utilities/microservice-utilities-tests.ts new file mode 100644 index 0000000000..3563e7fa8e --- /dev/null +++ b/types/microservice-utilities/microservice-utilities-tests.ts @@ -0,0 +1,13 @@ +import { Authorizer, PlatformClient, RequestLogger, ServiceTokenProvider } from 'microservice-utilities'; + +const authorizer = new Authorizer((msg: any) => msg, {jwkKeyListUrl: 'aaa'}); +const authorizerPolicy = authorizer.getPolicy({test: true}); + +const platformClient = new PlatformClient((msg: any) => msg); +platformClient.get('https://www.typescriptlang.org/'); +platformClient.post('https://www.typescriptlang.org/', {testData: 'abc'}); + +const serviceTokenProvider = new ServiceTokenProvider(platformClient, {}); + +const requestLogger = new RequestLogger({jsonSpace: 4}); +requestLogger.log('hello world'); diff --git a/types/microservice-utilities/tsconfig.json b/types/microservice-utilities/tsconfig.json new file mode 100644 index 0000000000..1e1845c7e8 --- /dev/null +++ b/types/microservice-utilities/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "microservice-utilities-tests.ts" + ] +} diff --git a/types/microservice-utilities/tslint.json b/types/microservice-utilities/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/microservice-utilities/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From 35483b43559b94114dca755f130e6ccb48f18d3b Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 26 Nov 2018 20:30:14 +0100 Subject: [PATCH 125/792] Impove types for bitwise-xor --- types/bitwise-xor/bitwise-xor-tests.ts | 12 ++-- types/bitwise-xor/index.d.ts | 7 +-- types/bitwise-xor/tsconfig.json | 4 +- types/bitwise-xor/tslint.json | 78 +------------------------- 4 files changed, 11 insertions(+), 90 deletions(-) diff --git a/types/bitwise-xor/bitwise-xor-tests.ts b/types/bitwise-xor/bitwise-xor-tests.ts index b19768f11f..13ddab8b66 100644 --- a/types/bitwise-xor/bitwise-xor-tests.ts +++ b/types/bitwise-xor/bitwise-xor-tests.ts @@ -1,10 +1,8 @@ +'use strict'; +import xor = require('bitwise-xor'); -"use strict"; +let b: Buffer; -import xor = require("bitwise-xor"); - -var b: Buffer; - -b = xor("a", "b"); -b = xor(new Buffer("a"), new Buffer("b")); +b = xor('a', 'b'); +b = xor(new Buffer('a'), new Buffer('b')); diff --git a/types/bitwise-xor/index.d.ts b/types/bitwise-xor/index.d.ts index 9960023c97..3147c5b675 100644 --- a/types/bitwise-xor/index.d.ts +++ b/types/bitwise-xor/index.d.ts @@ -1,15 +1,14 @@ -// Type definitions for bitwise-xor 0.0.0 +// Type definitions for bitwise-xor 0.0 // Project: https://github.com/czzarr/node-bitwise-xor // Definitions by: Rogier Schouten +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// - /** * Bitwise XOR between two Buffers or Strings, returns a Buffer */ -declare function xor(b1: Buffer, b2: Buffer): Buffer; -declare function xor(s1: string, s2: string): Buffer; +declare function xor(a: Buffer | string, b: Buffer | string): Buffer; export = xor; diff --git a/types/bitwise-xor/tsconfig.json b/types/bitwise-xor/tsconfig.json index a6b66cda37..f02f5ef72b 100644 --- a/types/bitwise-xor/tsconfig.json +++ b/types/bitwise-xor/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -20,4 +20,4 @@ "index.d.ts", "bitwise-xor-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/bitwise-xor/tslint.json b/types/bitwise-xor/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/bitwise-xor/tslint.json +++ b/types/bitwise-xor/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From c830fd6999d65e1c02f3be796233fb380f396826 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 26 Nov 2018 21:00:12 +0100 Subject: [PATCH 126/792] Add types for create-hash --- types/create-hash/create-hash-tests.ts | 9 +++++++++ types/create-hash/index.d.ts | 26 ++++++++++++++++++++++++++ types/create-hash/tsconfig.json | 23 +++++++++++++++++++++++ types/create-hash/tslint.json | 1 + 4 files changed, 59 insertions(+) create mode 100644 types/create-hash/create-hash-tests.ts create mode 100644 types/create-hash/index.d.ts create mode 100644 types/create-hash/tsconfig.json create mode 100644 types/create-hash/tslint.json diff --git a/types/create-hash/create-hash-tests.ts b/types/create-hash/create-hash-tests.ts new file mode 100644 index 0000000000..d039a5a704 --- /dev/null +++ b/types/create-hash/create-hash-tests.ts @@ -0,0 +1,9 @@ +import createHash = require('create-hash'); + +const hash = createHash('sha224'); + +hash.update('synchronous write'); +hash.digest(); +hash.write('write to it as a stream'); +hash.end(); +hash.read(); diff --git a/types/create-hash/index.d.ts b/types/create-hash/index.d.ts new file mode 100644 index 0000000000..712be2520f --- /dev/null +++ b/types/create-hash/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for create-hash 1.2 +// Project: https://github.com/crypto-browserify/createHash +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import { Hash } from 'crypto'; + +export = createHash; + +declare function createHash(algo: createHash.Algorithm): Hash; + +declare namespace createHash { + type Algorithm = + | 'md5' + | 'rmd160' + | 'ripemd160' + | 'sha' + | 'sha1' + | 'sha224' + | 'sha256' + | 'sha384' + | 'sha512'; +} diff --git a/types/create-hash/tsconfig.json b/types/create-hash/tsconfig.json new file mode 100644 index 0000000000..83e50b425c --- /dev/null +++ b/types/create-hash/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "create-hash-tests.ts" + ] +} diff --git a/types/create-hash/tslint.json b/types/create-hash/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/create-hash/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b41337dd487ca3a99359e93a9067073643870d99 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 26 Nov 2018 21:15:37 +0100 Subject: [PATCH 127/792] Add types for create-hmac --- types/create-hmac/create-hmac-tests.ts | 9 +++++++++ types/create-hmac/index.d.ts | 26 ++++++++++++++++++++++++++ types/create-hmac/tsconfig.json | 23 +++++++++++++++++++++++ types/create-hmac/tslint.json | 1 + 4 files changed, 59 insertions(+) create mode 100644 types/create-hmac/create-hmac-tests.ts create mode 100644 types/create-hmac/index.d.ts create mode 100644 types/create-hmac/tsconfig.json create mode 100644 types/create-hmac/tslint.json diff --git a/types/create-hmac/create-hmac-tests.ts b/types/create-hmac/create-hmac-tests.ts new file mode 100644 index 0000000000..f233a0390a --- /dev/null +++ b/types/create-hmac/create-hmac-tests.ts @@ -0,0 +1,9 @@ +import createHmac = require('create-hmac'); + +const hmac = createHmac('sha224', Buffer.from('secret key')); + +hmac.update('synchronous write'); +hmac.digest(); +hmac.write('write to it as a stream'); +hmac.end(); +hmac.read(); diff --git a/types/create-hmac/index.d.ts b/types/create-hmac/index.d.ts new file mode 100644 index 0000000000..3d6bcfeafa --- /dev/null +++ b/types/create-hmac/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for create-hmac 1.1 +// Project: https://github.com/crypto-browserify/createHmac +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import { Hmac } from 'crypto'; + +export = createHmac; + +declare function createHmac(algo: createHmac.Algorithm, key: string | Buffer): Hmac; + +declare namespace createHmac { + type Algorithm = + | 'rmd160' + | 'ripemd160' + | 'md5' + | 'sha' + | 'sha1' + | 'sha224' + | 'sha256' + | 'sha384' + | 'sha512'; +} diff --git a/types/create-hmac/tsconfig.json b/types/create-hmac/tsconfig.json new file mode 100644 index 0000000000..badd99da29 --- /dev/null +++ b/types/create-hmac/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "create-hmac-tests.ts" + ] +} diff --git a/types/create-hmac/tslint.json b/types/create-hmac/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/create-hmac/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From afe5664ded8cec5ccf443e2dd682298f5b53c5b7 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 26 Nov 2018 21:41:06 +0100 Subject: [PATCH 128/792] Add types for sha.js --- types/sha.js/index.d.ts | 26 ++++++++++++++++++++++++++ types/sha.js/sha.js-tests.ts | 15 +++++++++++++++ types/sha.js/tsconfig.json | 23 +++++++++++++++++++++++ types/sha.js/tslint.json | 1 + 4 files changed, 65 insertions(+) create mode 100644 types/sha.js/index.d.ts create mode 100644 types/sha.js/sha.js-tests.ts create mode 100644 types/sha.js/tsconfig.json create mode 100644 types/sha.js/tslint.json diff --git a/types/sha.js/index.d.ts b/types/sha.js/index.d.ts new file mode 100644 index 0000000000..d5dc4ba752 --- /dev/null +++ b/types/sha.js/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for sha.js 2.4 +// Project: https://github.com/crypto-browserify/sha.js +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Hash } from 'crypto'; + +export = SHA; + +declare function SHA(algorithm: string): Hash; + +declare namespace SHA { + type Algorithm = 'sha' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512'; + interface HashStatic { + new (): Hash; + } + + const sha: HashStatic; + const sha1: HashStatic; + const sha224: HashStatic; + const sha256: HashStatic; + const sha384: HashStatic; + const sha512: HashStatic; +} diff --git a/types/sha.js/sha.js-tests.ts b/types/sha.js/sha.js-tests.ts new file mode 100644 index 0000000000..fd3cde2e47 --- /dev/null +++ b/types/sha.js/sha.js-tests.ts @@ -0,0 +1,15 @@ +import shajs = require('sha.js'); + +shajs('sha256') + .update('42') + .digest('hex'); +new shajs.sha().update('42').digest('hex'); +new shajs.sha1().update('42').digest('hex'); +new shajs.sha224().update('42').digest('hex'); +new shajs.sha256().update('42').digest('hex'); +new shajs.sha384().update('42').digest('hex'); +new shajs.sha512().update('42').digest('hex'); + +const sha256stream = shajs('sha256'); +sha256stream.end('42'); +(sha256stream.read() as Buffer).toString('hex'); diff --git a/types/sha.js/tsconfig.json b/types/sha.js/tsconfig.json new file mode 100644 index 0000000000..9f10462f5a --- /dev/null +++ b/types/sha.js/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "sha.js-tests.ts" + ] +} diff --git a/types/sha.js/tslint.json b/types/sha.js/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sha.js/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 9ed2a742a2989285e8ca98bbc3b3c418df508c72 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 26 Nov 2018 22:03:57 +0100 Subject: [PATCH 129/792] Add types for ripemd160 --- types/ripemd160/index.d.ts | 16 ++++++++++++++++ types/ripemd160/ripemd160-tests.ts | 7 +++++++ types/ripemd160/tsconfig.json | 23 +++++++++++++++++++++++ types/ripemd160/tslint.json | 1 + 4 files changed, 47 insertions(+) create mode 100644 types/ripemd160/index.d.ts create mode 100644 types/ripemd160/ripemd160-tests.ts create mode 100644 types/ripemd160/tsconfig.json create mode 100644 types/ripemd160/tslint.json diff --git a/types/ripemd160/index.d.ts b/types/ripemd160/index.d.ts new file mode 100644 index 0000000000..27de423a18 --- /dev/null +++ b/types/ripemd160/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for ripemd160 2.0 +// Project: https://github.com/crypto-browserify/ripemd160#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Hash } from 'crypto'; + +export = RIPEMD160; + +declare const RIPEMD160: RIPEMD160Static; + +interface RIPEMD160Static { + new (): Hash; +} diff --git a/types/ripemd160/ripemd160-tests.ts b/types/ripemd160/ripemd160-tests.ts new file mode 100644 index 0000000000..3a78efbac3 --- /dev/null +++ b/types/ripemd160/ripemd160-tests.ts @@ -0,0 +1,7 @@ +import RIPEMD160 = require('ripemd160'); + +new RIPEMD160().update('42').digest('hex'); + +const ripemd160stream = new RIPEMD160(); +ripemd160stream.end('42'); +(ripemd160stream.read() as Buffer).toString('hex'); diff --git a/types/ripemd160/tsconfig.json b/types/ripemd160/tsconfig.json new file mode 100644 index 0000000000..07abc9bd05 --- /dev/null +++ b/types/ripemd160/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ripemd160-tests.ts" + ] +} diff --git a/types/ripemd160/tslint.json b/types/ripemd160/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ripemd160/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 9fa2b6599f6309a7e33e5b5ab1387537ed68d9df Mon Sep 17 00:00:00 2001 From: Boris Sergeyev Date: Mon, 26 Nov 2018 22:18:35 +0100 Subject: [PATCH 130/792] [react-redux] extended ThunkActionCreator testsuite to check all overloads --- types/react-redux/react-redux-tests.tsx | 59 ++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index f47683047e..554ace09ff 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -120,12 +120,61 @@ function MapDispatchWithThunkActionCreators() { } class TestComponent extends React.Component {} - const Test = connect( - null, - ({ simpleAction, thunkAction }), - )(TestComponent); + const mapStateToProps = ({ foo }: { foo: string }) => ({ foo }); + const mapDispatchToProps = { simpleAction, thunkAction }; - const verify = ; + const Test1 = connect(null, mapDispatchToProps)(TestComponent); + const Test2 = connect(mapStateToProps, mapDispatchToProps)(TestComponent); + const Test3 = connect( + null, mapDispatchToProps, null, { storeKey: 'somekey' } + )(TestComponent); + const Test4 = connect( + mapStateToProps, mapDispatchToProps, null, { storeKey: 'somekey' } + )(TestComponent); + const verify =
+ ; + + ; + +
; +} + +function MapManualDispatchThatLooksLikeThunk() { + interface OwnProps { + foo: string; + } + interface TestComponentProps extends OwnProps { + remove: (item: string) => () => object; + } + class TestComponent extends React.Component { + render() { + return
; + } + } + + const mapStateToProps = ({ foo }: { foo: string }) => ({ foo }); + function mapDispatchToProps(dispatch: Dispatch) { + return { + remove(item: string) { + return () => dispatch({ type: 'REMOVE_ITEM', item }); + } + }; + } + + const Test1 = connect(null, mapDispatchToProps)(TestComponent); + const Test2 = connect(mapStateToProps, mapDispatchToProps)(TestComponent); + const Test3 = connect( + null, mapDispatchToProps, null, { storeKey: 'somekey' } + )(TestComponent); + const Test4 = connect( + mapStateToProps, mapDispatchToProps, null, { storeKey: 'somekey' } + )(TestComponent); + const verify =
+ ; + + ; + +
; } function MapStateAndDispatchObject() { From 8cbf6d938de2e838a4f3cc9695576958ed55f4c3 Mon Sep 17 00:00:00 2001 From: Boris Sergeyev Date: Mon, 26 Nov 2018 22:19:18 +0100 Subject: [PATCH 131/792] [react-redux] fixed type definitions to pass extended tests --- types/react-redux/index.d.ts | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index bf65d89fd5..dc8a9af912 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -160,7 +160,12 @@ export interface Connect { ( mapStateToProps: null | undefined, - mapDispatchToProps: MapDispatchToPropsParam + mapDispatchToProps: MapDispatchToPropsNonObject + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: null | undefined, + mapDispatchToProps: TDispatchProps, ): InferableComponentEnhancerWithProps< WithThunkActionCreators, TOwnProps @@ -168,7 +173,12 @@ export interface Connect { ( mapStateToProps: MapStateToPropsParam, - mapDispatchToProps: MapDispatchToPropsParam + mapDispatchToProps: MapDispatchToPropsNonObject + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: MapStateToPropsParam, + mapDispatchToProps: TDispatchProps, ): InferableComponentEnhancerWithProps< TStateProps & WithThunkActionCreators, TOwnProps @@ -208,7 +218,14 @@ export interface Connect { ( mapStateToProps: null | undefined, - mapDispatchToProps: MapDispatchToPropsParam, + mapDispatchToProps: MapDispatchToPropsNonObject, + mergeProps: null | undefined, + options: Options<{}, TStateProps, TOwnProps> + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: null | undefined, + mapDispatchToProps: TDispatchProps, mergeProps: null | undefined, options: Options<{}, TStateProps, TOwnProps> ): InferableComponentEnhancerWithProps< @@ -218,7 +235,14 @@ export interface Connect { ( mapStateToProps: MapStateToPropsParam, - mapDispatchToProps: MapDispatchToPropsParam, + mapDispatchToProps: MapDispatchToPropsNonObject, + mergeProps: null | undefined, + options: Options + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: MapStateToPropsParam, + mapDispatchToProps: TDispatchProps, mergeProps: null | undefined, options: Options ): InferableComponentEnhancerWithProps< @@ -248,10 +272,12 @@ export type MapDispatchToProps = MapDispatchToPropsFunction | TDispatchProps; export type MapDispatchToPropsFactory = - (dispatch: Dispatch, ownProps: TOwnProps) => MapDispatchToProps; + (dispatch: Dispatch, ownProps: TOwnProps) => MapDispatchToPropsFunction; export type MapDispatchToPropsParam = MapDispatchToPropsFactory | MapDispatchToProps; +export type MapDispatchToPropsNonObject = MapDispatchToPropsFactory | MapDispatchToPropsFunction; + export type MergeProps = (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps) => TMergedProps; From 009260118e5ebe5a5afe3ebf749998d69e0e5ea7 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 25 Nov 2018 23:53:43 +0100 Subject: [PATCH 132/792] Add types for saslmechanisms --- types/saslmechanisms/index.d.ts | 31 ++++++++++++++++++++ types/saslmechanisms/saslmechanisms-tests.ts | 22 ++++++++++++++ types/saslmechanisms/tsconfig.json | 23 +++++++++++++++ types/saslmechanisms/tslint.json | 1 + 4 files changed, 77 insertions(+) create mode 100644 types/saslmechanisms/index.d.ts create mode 100644 types/saslmechanisms/saslmechanisms-tests.ts create mode 100644 types/saslmechanisms/tsconfig.json create mode 100644 types/saslmechanisms/tslint.json diff --git a/types/saslmechanisms/index.d.ts b/types/saslmechanisms/index.d.ts new file mode 100644 index 0000000000..62f71e8a25 --- /dev/null +++ b/types/saslmechanisms/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for saslmechanisms 0.1 +// Project: https://github.com/jaredhanson/js-sasl +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = Factory; + +declare class Factory { + static Factory: typeof Factory; + + use(name: string, mechanism: Factory.MechanismStatic): this; + use(mechanism: Factory.MechanismStatic): this; + create(mechanisms: string[]): Factory.Mechanism | null; +} + +declare namespace Factory { + interface MechanismStatic { + new (): Mechanism; + prototype: { + [key: string]: any; + name: string; + }; + } + interface Mechanism { + name: string; + + response(cred: { [key: string]: any }): string; + + challenge(chal: string): void; + } +} diff --git a/types/saslmechanisms/saslmechanisms-tests.ts b/types/saslmechanisms/saslmechanisms-tests.ts new file mode 100644 index 0000000000..d7e6fe7620 --- /dev/null +++ b/types/saslmechanisms/saslmechanisms-tests.ts @@ -0,0 +1,22 @@ +import Fct = require('saslmechanisms'); +import { Factory, MechanismStatic, Mechanism } from 'saslmechanisms'; + +const Mech: MechanismStatic = null as any; + +const factory = new Fct(); +new Factory(); +new Factory.Factory(); + +// $ExpectType Factory +factory.use(Mech); +factory.use('Mech', Mech); + +const mech: Mechanism | null = factory.create(['Mech']); +if (mech) { + // $ExpectType string + mech.name; + // $ExpectType string + mech.response({ foo: 'bar' }); + // $ExpectType void + mech.challenge('challenge'); +} diff --git a/types/saslmechanisms/tsconfig.json b/types/saslmechanisms/tsconfig.json new file mode 100644 index 0000000000..64beedfc0f --- /dev/null +++ b/types/saslmechanisms/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "saslmechanisms-tests.ts" + ] +} diff --git a/types/saslmechanisms/tslint.json b/types/saslmechanisms/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/saslmechanisms/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 84bc355df06ea07679ab0634483c08f76ac4bb7c Mon Sep 17 00:00:00 2001 From: Boris Sergeyev Date: Tue, 27 Nov 2018 07:18:16 +0100 Subject: [PATCH 133/792] [react-redux] improved naming of higher-order-type that handles thunks --- types/react-redux/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index dc8a9af912..bcbcced0bd 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -112,19 +112,19 @@ export type InferableComponentEnhancerWithProps = export type InferableComponentEnhancer = InferableComponentEnhancerWithProps; -export type WrappedThunkActionCreator any> = +export type InferThunkActionCreatorType any> = TActionCreator extends (...args: infer TParams) => (...args: any[]) => infer TReturn ? (...args: TParams) => TReturn : TActionCreator; export type HandleThunkActionCreator = TActionCreator extends (...args: any[]) => any - ? WrappedThunkActionCreator + ? InferThunkActionCreatorType : TActionCreator; // redux-thunk middleware returns thunk's return value from dispatch call // https://github.com/reduxjs/redux-thunk#composition -export type WithThunkActionCreators = +export type ResolveThunks = TDispatchProps extends { [key: string]: any } ? { [C in keyof TDispatchProps]: HandleThunkActionCreator @@ -167,7 +167,7 @@ export interface Connect { mapStateToProps: null | undefined, mapDispatchToProps: TDispatchProps, ): InferableComponentEnhancerWithProps< - WithThunkActionCreators, + ResolveThunks, TOwnProps >; @@ -180,7 +180,7 @@ export interface Connect { mapStateToProps: MapStateToPropsParam, mapDispatchToProps: TDispatchProps, ): InferableComponentEnhancerWithProps< - TStateProps & WithThunkActionCreators, + TStateProps & ResolveThunks, TOwnProps >; @@ -229,7 +229,7 @@ export interface Connect { mergeProps: null | undefined, options: Options<{}, TStateProps, TOwnProps> ): InferableComponentEnhancerWithProps< - WithThunkActionCreators, + ResolveThunks, TOwnProps >; @@ -246,7 +246,7 @@ export interface Connect { mergeProps: null | undefined, options: Options ): InferableComponentEnhancerWithProps< - TStateProps & WithThunkActionCreators, + TStateProps & ResolveThunks, TOwnProps >; // tslint:enable:no-unnecessary-generics From 7e23c69081ef5211b821463eb9c223e891c7a456 Mon Sep 17 00:00:00 2001 From: Nokky Goren <30292793+ApeNox@users.noreply.github.com> Date: Tue, 27 Nov 2018 16:31:11 +0200 Subject: [PATCH 134/792] Update definitions to accommodate API changes InputProps are now optional. The Component now receives props via direct application. --- types/react-places-autocomplete/index.d.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/types/react-places-autocomplete/index.d.ts b/types/react-places-autocomplete/index.d.ts index 62e3d93a1d..26046fc06f 100644 --- a/types/react-places-autocomplete/index.d.ts +++ b/types/react-places-autocomplete/index.d.ts @@ -15,9 +15,7 @@ export interface formattedSuggestionType { } export interface PropTypes { - inputProps: { - value: string; - onChange: (value: string) => void; + inputProps?: { type?: string; name?: string; placeholder?: string; @@ -49,6 +47,9 @@ export interface PropTypes { radius?: number | string; types?: string[]; }; + value: string; + onChange?: (value: string) => void; + onBlur?: (event: React.FocusEvent) => void; debounce?: number; highlightFirstSuggestion?: boolean; From f5e979aa4e03525afab03c4bff3c339762b57314 Mon Sep 17 00:00:00 2001 From: Nokky Goren <30292793+ApeNox@users.noreply.github.com> Date: Tue, 27 Nov 2018 16:53:21 +0200 Subject: [PATCH 135/792] fix optional inputs --- types/react-places-autocomplete/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/react-places-autocomplete/index.d.ts b/types/react-places-autocomplete/index.d.ts index 26046fc06f..f95164a89d 100644 --- a/types/react-places-autocomplete/index.d.ts +++ b/types/react-places-autocomplete/index.d.ts @@ -19,7 +19,6 @@ export interface PropTypes { type?: string; name?: string; placeholder?: string; - onBlur?: (event: React.FocusEvent) => void; disabled?: boolean; }; onError?: (status: string, clearSuggestion: () => void) => void; @@ -47,7 +46,7 @@ export interface PropTypes { radius?: number | string; types?: string[]; }; - value: string; + value?: string; onChange?: (value: string) => void; onBlur?: (event: React.FocusEvent) => void; From f4f4074e189ffb8b461566c4430bd3d4620daa17 Mon Sep 17 00:00:00 2001 From: Nokky Goren <30292793+ApeNox@users.noreply.github.com> Date: Tue, 27 Nov 2018 16:55:07 +0200 Subject: [PATCH 136/792] Update types version --- types/react-places-autocomplete/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-places-autocomplete/index.d.ts b/types/react-places-autocomplete/index.d.ts index f95164a89d..19d53c863d 100644 --- a/types/react-places-autocomplete/index.d.ts +++ b/types/react-places-autocomplete/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-places-autocomplete 6.1 +// Type definitions for react-places-autocomplete 7 // Project: https://github.com/kenny-hibino/react-places-autocomplete/ // Definitions by: Guilherme HΓΌbner // Andrew Makarov From 0a3010fe25eaded32b64e515df877479ca13cb53 Mon Sep 17 00:00:00 2001 From: Nokky Goren <30292793+ApeNox@users.noreply.github.com> Date: Tue, 27 Nov 2018 16:57:11 +0200 Subject: [PATCH 137/792] Update Tests --- .../react-places-autocomplete-tests.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-places-autocomplete/react-places-autocomplete-tests.tsx b/types/react-places-autocomplete/react-places-autocomplete-tests.tsx index 41e6ff37b4..a7a7816d99 100644 --- a/types/react-places-autocomplete/react-places-autocomplete-tests.tsx +++ b/types/react-places-autocomplete/react-places-autocomplete-tests.tsx @@ -45,7 +45,7 @@ class Test extends React.Component { return (
- + ); } From 4731065fe25d5aa1e192166802321482db70dd21 Mon Sep 17 00:00:00 2001 From: Nokky Goren <30292793+ApeNox@users.noreply.github.com> Date: Tue, 27 Nov 2018 17:02:42 +0200 Subject: [PATCH 138/792] Update index.d.ts --- types/react-places-autocomplete/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-places-autocomplete/index.d.ts b/types/react-places-autocomplete/index.d.ts index 19d53c863d..6a6a85c19e 100644 --- a/types/react-places-autocomplete/index.d.ts +++ b/types/react-places-autocomplete/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-places-autocomplete 7 +// Type definitions for react-places-autocomplete 7.2 // Project: https://github.com/kenny-hibino/react-places-autocomplete/ // Definitions by: Guilherme HΓΌbner // Andrew Makarov From c7f49bd2d0d3e9f5cd066b6e340db5f404a0d212 Mon Sep 17 00:00:00 2001 From: dasimple Date: Tue, 27 Nov 2018 18:47:12 +0200 Subject: [PATCH 139/792] First typings for gdal package --- types/gdal/gdal-tests.ts | 78 ++++ types/gdal/index.d.ts | 764 +++++++++++++++++++++++++++++++++++++++ types/gdal/tsconfig.json | 22 ++ types/gdal/tslint.json | 1 + 4 files changed, 865 insertions(+) create mode 100644 types/gdal/gdal-tests.ts create mode 100644 types/gdal/index.d.ts create mode 100644 types/gdal/tsconfig.json create mode 100644 types/gdal/tslint.json diff --git a/types/gdal/gdal-tests.ts b/types/gdal/gdal-tests.ts new file mode 100644 index 0000000000..d30c83d571 --- /dev/null +++ b/types/gdal/gdal-tests.ts @@ -0,0 +1,78 @@ +import * as gdal from 'gdal'; + +// gdal.checksumImage(srcRasterBand, 0, 0, 512, 512); + +gdal.config.get('GDAL_DATA'); +gdal.config.set('GDAL_DATA', 'C:\\warmerda\\bld\\data'); + +/*gdal.contourGenerate({ + src: srcRasterBand, + dst: dstRasterBand +});*/ + +gdal.decToDMS(60, 'lat'); +gdal.decToDMS(60, 'lat', 2); + +/*gdal.fillNodata({ + +});*/ + +let creationOptionsArray: string[]; +creationOptionsArray = ['VRT_CREATION_OPTION=...']; +let creationOptionsObject: object; +creationOptionsObject = { + VRT_CREATION_OPTION: '...' +}; +gdal.open('C:\\datasets\\ogr.shp'); +gdal.open('C:\\datasets\\ogr.shp', 'r'); +gdal.open('C:\\datasets\\ogr.shp', 'r', 'ESRI Shapefile'); +gdal.open('C:\\datasets\\ogr.shp', 'r', ['ESRI Shapefile']); +gdal.open('C:\\datasets\\ogr.shp', 'r+'); +gdal.open('C:\\datasets\\ogr.shp', 'r+', 'ESRI Shapefile'); +gdal.open('C:\\datasets\\ogr.shp', 'r+', ['ESRI Shapefile']); +gdal.open('C:\\datasets\\raster.vrt', 'w', 'VRT'); +gdal.open('C:\\datasets\\raster.vrt', 'w', 'VRT', 512, 512, 3, 1, creationOptionsArray); +gdal.open('C:\\datasets\\raster.vrt', 'w', 'VRT', 512, 512, 3, 1, creationOptionsObject); +gdal.open('C:\\datasets\\raster.vrt', 'w', ['VRT']); +gdal.open('C:\\datasets\\raster.vrt', 'w', ['VRT'], 512, 512, 3, 1, creationOptionsArray); +gdal.open('C:\\datasets\\raster.vrt', 'w', ['VRT'], 512, 512, 3, 1, creationOptionsObject); + +/*let polygonizeOptions: gdal.PolygonizeOptions; +polygonizeOptions = { + src: srcRasterBand, + dst: dstRasterBand, + connectedness: 1, + mask: maskRasterBand, + pixValField: 1, + useFloats: true +}; +gdal.polygonize(polygonizeOptions); +gdal.polygonize({ + src: srcRasterBand, + dst: dstRasterBand, + pixValField: 1 +});*/ + +gdal.quiet(); + +/*let reprojectImageOptions: gdal.ReprojectImageOptions; +reprojectImageOptions = { + src: srcRasterBand, + dst: dstRasterBand, + s_srs: sourceSRS, + t_srs: targetSRS +}; +gdal.reprojectImage(reprojectImageOptions); +gdal.reprojectImage({ + +}); + +gdal.sieveFilter({ + +}); + +gdal.suggestedWarpOutput({ + +});*/ + +gdal.verbose(); diff --git a/types/gdal/index.d.ts b/types/gdal/index.d.ts new file mode 100644 index 0000000000..50280cff3d --- /dev/null +++ b/types/gdal/index.d.ts @@ -0,0 +1,764 @@ +// Type definitions for gdal 0.9 +// Project: https://github.com/naturalatlas/node-gdal#readme +// Definitions by: Andrei Digori +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +export as namespace gdal; + +/* Internal interfaces */ + +export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; +export type Resampling = 'NEAREST' | 'GAUSS' | 'CUBIC' | 'AVERAGE' | 'MODE' | 'AVERAGE_MAGPHASE' | 'NONE'; + +export interface XY +{ + x: number; + y: number; +} + +export interface XYZ extends XY +{ + z: number; +} + +export interface EnvelopeBounds +{ + minX: number, + maxX: number, + minY: number, + maxY: number +} + +export interface Envelope3DBounds extends EnvelopeBounds +{ + minZ: number, + maxZ: number +} + +export interface RasterBandStatistics +{ + min: number; + max: number; + mean: number; + std_dev: number; +} + +export interface RasterBandPixelsWriteOptions +{ + buffer_width?: number; + buffer_height?: number; + pixel_space?: number; + line_space?: number; +} + +export interface RasterBandPixelsReadOptions +{ + buffer_width?: number; + buffer_height?: number; + pixel_space?: number; + line_space?: number; + data_type?: string; +} + +export interface ContourGenerateOptions +{ + src: RasterBand; + dst: Layer; + offset?: number; + interval?: number; + fixedLevels?: number[]; + nodata?: number; + idField?: number; + elevField?: number; +} + +export interface FillNoDataOptions +{ + src: RasterBand; + mask?: RasterBand; + searchDist: number; + smoothingIterations?: number; +} + +export interface PolygonizeOptions +{ + src: RasterBand; + dst: Layer; + mask?: RasterBand; + pixValField: number; + connectedness?: number; + useFloats?: boolean; +} + +export interface ReprojectImageOptions +{ + src: Dataset; + dst: Dataset; + s_srs: SpatialReference; + t_srs: SpatialReference; + resampling?: string; + cutline?: Geometry; + srcBands?: number[]; + dstBands?: number[]; + srcAlphaBand?: number; + dstAlphaBand?: number; + srcNodata?: number; + dstNodata?: number; + memoryLimit?: number; + maxError?: number; + multi?: boolean; + options?: string[] | object; +} + +export interface SieveFilterOptions +{ + src: RasterBand; + dst: RasterBand; + mask?: RasterBand; + threshold: number; + connectedness?: number; +} + +export interface SuggestedWarpOutputOptions +{ + src: Dataset; + s_srs: SpatialReference; + t_srs: SpatialReference; + maxError?: number; +} + +/* From API: https://naturalatlas.github.io/node-gdal/ */ + +/* Constants */ + +// CPL Error Codes +export const CPLE_AppDefined: number; +export const CPLE_AssertionFailed: number; +export const CPLE_FileIO: number; +export const CPLE_IllegalArg: number; +export const CPLE_None: number; +export const CPLE_NotSupported: number; +export const CPLE_NoWriteAccess: number; +export const CPLE_ObjectNull: number; +export const CPLE_OpenFailed: number; +export const CPLE_OutOfMemory: number; +export const CPLE_UserInterrupt: number; + +// CPL Error Levels +export const CE_Debug: number; +export const CE_Failure: number; +export const CE_Fatal: number; +export const CE_None: number; +export const CE_Warning: number; + +// DCAP +export const DCAP_CREATE: string; +export const DCAP_CREATECOPY: string; +export const DCAP_VIRTUALIO: string; + +// DMD +export const DMD_CREATIONDATATYPES: string; +export const DMD_CREATIONOPTIONLIST: string; +export const DMD_EXTENSION: string; +export const DMD_HELPTOPIC: string; +export const DMD_LONGNAME: string; +export const DMD_MIMETYPE: string; + +// GCI +export const GCI_AlphaBand: string; +export const GCI_BlackBand: string; +export const GCI_BlueBand: string; +export const GCI_CyanBand: string; +export const GCI_GrayIndex: string; +export const GCI_GreenBand: string; +export const GCI_HueBand: string; +export const GCI_LightnessBand: string; +export const GCI_MagentaBand: string; +export const GCI_PaletteIndex: string; +export const GCI_RedBand: string; +export const GCI_SaturationBand: string; +export const GCI_Undefined: string; +export const GCI_YCbCr_CbBand: string; +export const GCI_YCbCr_CrBand: string; +export const GCI_YCbCr_YBand: string; +export const GCI_YellowBand: string; + +// GDT +export const GDT_Byte: string; +export const GDT_CFloat32: string; +export const GDT_CFloat64: string; +export const GDT_CInt16: string; +export const GDT_CInt32: string; +export const GDT_Float32: string; +export const GDT_Float64: string; +export const GDT_Int16: string; +export const GDT_Int32: string; +export const GDT_UInt16: string; +export const GDT_UInt32: string; +export const GDT_Unknown: string; + +// GRA +export const GRA_Average: string; +export const GRA_Bilinear: string; +export const GRA_Cubic: string; +export const GRA_CubicSpline: string; +export const GRA_Lanczos: string; +export const GRA_Mode: string; +export const GRA_NearestNeighbor: string; + +// ODsC +export const ODrCCreateDataSource: string; +export const ODrCDeleteDataSource: string; +export const ODsCCreateGeomFieldAfterCreateLayer: string; +export const ODsCCreateLayer: string; +export const ODsCDeleteLayer: string; + +// OFT +export const OFTBinary: string; +export const OFTDate: string; +export const OFTDateTime: string; +export const OFTInteger: string; +export const OFTIntegerList: string; +export const OFTReal: string; +export const OFTRealList: string; +export const OFTString: string; +export const OFTStringList: string; +export const OFTTime: string; +export const OFTWideString: string; +export const OFTWideStringList: string; + +// OJ +export const OJLeft: string; +export const OJRight: string; +export const OJUndefined: string; + +// OLC +export const OLCAlterFieldDefn: string; +export const OLCCreateField: string; +export const OLCCreateGeomField: string; +export const OLCDeleteFeature: string; +export const OLCDeleteField: string; +export const OLCFastFeatureCount: string; +export const OLCFastGetExtent: string; +export const OLCFastSetNextByIndex: string; +export const OLCFastSpatialFilter: string; +export const OLCIgnoreFields: string; +export const OLCRandomRead: string; +export const OLCRandomWrite: string; +export const OLCReorderFields: string; +export const OLCSequentialWrite: string; +export const OLCStringsAsUTF8: string; +export const OLCTransactions: string; + +// wkbByteOrder +export const wkbNDR: string; +export const wkbXDR: string; + +// wkbGeometryType +export const wkb25DBit: number; +export const wkbGeometryCollection: number; +export const wkbGeometryCollection25D: number; +export const wkbLinearRing: string; +export const wkbLinearRing25D: number; +export const wkbLineString: number; +export const wkbLineString25D: number; +export const wkbMultiLineString: number; +export const wkbMultiLineString25D: number; +export const wkbMultiPoint: number; +export const wkbMultiPoint25D: number; +export const wkbMultiPolygon: number; +export const wkbMultiPolygon25D: number; +export const wkbNone: number; +export const wkbPoint: number; +export const wkbPoint25D: number; +export const wkbPolygon: number; +export const wkbPolygon25D: number; +export const wkbUnknown: number; + +// wkbVariant +export const wkbVariantIso: string; +export const wkbVariantOgc: string; +export const wkbVariantOldOgc: string; + +/* Classes and interfaces */ + +export class CoordinateTransformation +{ + constructor(source: SpatialReference, target: SpatialReference | Dataset); + transformPoint(x: number, y: number, z?: number): XYZ; +} + +export interface Dataset +{ + buildOverviews(resampling: Resampling, overviews: number[], bands?: number[]): void; + close(): void; + executeSQL(statement: string, spatial_filter?: Geometry, dialect?: string): Layer; + flush(): void; + getFileList(): string[]; + getGCPProjection(): string; + getGCPs(): object[]; + getMetadata(domain?: string): object; + setGCPs(gcps: object[], projection: string): void; + testCapability(capability: string): boolean; + + readonly bands: DatasetBands; + readonly description: string; + readonly driver: Driver; + geoTransform: number[]; + readonly layers: DatasetLayers; + readonly rasterSize: XY; + srs: SpatialReference; +} + +export interface DatasetBands +{ + count(): number; + create(dataType: number): RasterBand; + forEach(callback: (band: RasterBand, i: number) => void): void; + get(id: number): RasterBand; + map(callback: (band: RasterBand, i: number) => T): T[]; + + readonly ds: Dataset; +} + +export interface DatasetLayers +{ + copy(src_lyr_name: string, dst_lyr_name: string, options?: object | string[]): Layer; + count(): number; + create(name: string, srs: SpatialReference, geomType: number | Function, creation_options: string[] | object): Layer; + forEach(callback: (layer: Layer, i: number) => void): void; + get(key: string | number): Layer; + map(callback: (layer: Layer, i: number) => T): T[]; + remove(index: number): void; + + readonly ds: Dataset; +} + +export interface Driver +{ + copyFiles(name_old: string, name_new: string): void; + create(filename: string, x_size?: number, y_size?: number, band_count?: number, data_type?: number, creation_options?: string[] | object): Dataset; + createCopy(filename: string, src: Dataset, strict?: boolean, options?: string[] | object): Dataset; + deleteDataset(filename: string): void; + getMetadata(domain?: string): object; + open(path: string, mode?: 'r' | 'r+'): Dataset; + rename(new_name: string, old_name: string): void; + + readonly description: string; +} + +export class Envelope +{ + constructor(bounds: EnvelopeBounds); + contains(envelope: Envelope): boolean; + intersect(envelope: Envelope): void; + intersects(envelope: Envelope): boolean; + isEmpty(): boolean; + merge(envelope: Envelope): void; + toPolygon(): Polygon; +} + +export class Envelope3D extends Envelope +{ + constructor(bounds: Envelope3DBounds); +} + +export class Feature +{ + constructor(definition: Layer | FeatureDefn); + clone(): Feature; + destroy(): void; + equals(feature: Feature): boolean; + getFieldDefn(index: number): FieldDefn; + getGeometry(): Geometry; + setFrom(feature: Feature, index_map?: number[], forgiving?: boolean): void; + setGeometry(geometry: Geometry): void; + + readonly defn: FeatureDefn; + fid: number; + readonly fields: FeatureFields; +} + +export class FeatureDefn +{ + constructor(); + clone(): FeatureDefn; + + readonly fields: FeatureDefnFields; + geomIgnored: boolean; + geomType: number; + readonly name: string; + styleIgnored: boolean; +} + +export interface FeatureDefnFields +{ + add(field: FieldDefn | FieldDefn[]): void; + count(): number; + forEach(callback: (field: FieldDefn, i: number) => void): void; + get(key: string | number): FieldDefn; + getNames(): string[]; + indexOf(name: string): number; + map(callback: (field: FieldDefn, i: number) => T): T[]; + remove(key: string | number): void; + reorder(map: number[]): void; + + readonly featureDefn: FeatureDefn; +} + +export interface FeatureFields +{ + count(): number; + forEach(callback: (value: any, key: string) => void): void; + get(key: string | number): any; + getNames(): string[]; + indexOf(name: string): number; + map(callback: (value: any, key: string) => T): T[]; + reset(values: object, value: any): void; + set(key: string | number, value: any): void; + toArray(): any[]; + toJSON(): string; + toObject(): object; + + readonly feature: Feature; +} + +export class FieldDefn +{ + constructor(name: string, type: string); + + ignored: boolean; + justification: string; + name: string; + precision: number; + type: string; + width: number; +} + +export interface GDALDrivers +{ + count(): number; + forEach(callback: (driver: Driver, i: number) => void): void; + get(index: number | string): Driver; + getNames(): string[]; + map(callback: (driver: Driver, i: number) => T): T[]; +} + +export abstract class Geometry +{ + static create(type: number): Geometry; + static fromWKB(wkb: number, srs?: SpatialReference): Geometry; + static fromWKT(wkt: string, srs?: SpatialReference): Geometry; + static getConstructor(type: number): Function; + static getName(type: number): string; + + boundary(): Geometry; + buffer(distance: number, segments: number): Geometry; + centroid(): Point; + clone(): Geometry; + closeRings(): void; + contains(geometry: Geometry): boolean; + convexHull(): Geometry; + crosses(geometry: Geometry): boolean; + difference(geometry: Geometry): Geometry; + disjoint(geometry: Geometry): boolean; + distance(geometry: Geometry): number; + empty(): void; + equals(geometry: Geometry): boolean; + getEnvelope(): Envelope; + getEnvelope3D(): Envelope3D; + intersection(geometry: Geometry): Geometry; + intersects(geometry: Geometry): boolean; + isEmpty(): boolean; + isRing(): boolean; + isSimple(): boolean; + isValid(): boolean; + overlaps(geometry: Geometry): boolean; + segmentize(segment_length: number): number; + simplify(tolerance: number): Geometry; + simplifyPreserveTopology(tolerance: number): Geometry; + swapXY(): void; + symDifference(geometry: Geometry): Geometry; + toGML(): Geometry; + toJSON(): Geometry; + toKML(): Geometry; + toObject(): object; + touches(geometry: Geometry): boolean; + toWKB(byte_order?: string, variant?: string): Geometry; + toWKT(): Geometry; + transform(transformation: CoordinateTransformation): void; + transformTo(srs: SpatialReference): void; + union(geometry: Geometry): Geometry; + within(geometry: Geometry): boolean; + + readonly coordinateDimension: number; + readonly dimension: number; + readonly name: string; + srs: SpatialReference; + readonly wkbSize: number; + readonly wkbType: number; +} + +export class GeometryCollection extends Geometry +{ + getArea(): number; + getLength(): number; + + children: GeometryCollectionChildren; +} + +export interface GeometryCollectionChildren +{ + add(geometry: Geometry | Geometry[]): void; + count(): number; + forEach(callback: (geometry: Geometry, i: number) => void): void; + get(index: number): Geometry; + map(callback: (geometry: Geometry, i: number) => T): T[]; + remove(index: number): void; + toArray(): Geometry[]; + + readonly layer: Layer; +} + +export interface Layer +{ + flush(): void; + getExtent(force?: boolean): Envelope; + getSpatialFilter(): Geometry; + setAttributeFilter(filter: string): void; + setSpatialFilter(filter: Geometry): void; + setSpatialFilter(minX: number, maxX: number, minY: number, maxY: number): void; + testCapability(capability: string): boolean; + + readonly ds: Dataset; + readonly features: LayerFeatures; + readonly fidColumn: string; + readonly fields: LayerFields; + readonly geomColumn: string; + readonly geomType: number; + readonly name: string; + readonly srs: SpatialReference; +} + +export interface LayerFeatures +{ + add(feature: Feature): void; + count(force?: boolean): number; + first(): Feature; + forEach(callback: (feature: Feature, i: number) => void): void; + get(id: number): Feature; + map(callback: (feature: Feature, i: number) => T): T[]; + next(): Feature; + remove(id: number): void; + set(id: number, feature: Feature): void; + + readonly layer: Layer; +} + +export interface LayerFields +{ + add(def: FieldDefn | FieldDefn[], approx?: boolean): void; + count(): number; + forEach(callback: (field: FieldDefn, i: number) => void): void; + fromJSON(object: object, approx_ok?: boolean): LayerFields; + get(field: string | number): FieldDefn; + getNames(): string[]; + indexOf(field: string): number; + map(callback: (field: FieldDefn, i: number) => T): T[]; + remove(field: string | number): void; + reorder(map: number[]): void; + + readonly layer: Layer; +} + +export class LinearRing extends LineString +{ + getArea(): number; +} + +export class LineString extends Geometry +{ + addSubLineString(line: LineString, start?: number, end?: number): void; + getLength(): number; + value(distance: number): Point; + + readonly points: LineStringPoints; +} + +export interface LineStringPoints +{ + add(point: Point | Point[]): void; + count(): number; + forEach(callback: (point: Point, i: number) => void): void; + get(index: number): Point; + map(callback: (point: Point, i: number) => T): T[]; + remove(index: number): void; + resize(count: number): void; + reverse(): void; + set(index: number, point: Point): void; + toArray(): Point[]; +} + +export class MultiLineString extends GeometryCollection +{ + polygonize(): Polygon; +} + +export class MultiPoint extends GeometryCollection +{ + +} + +export class MultiPolygon extends GeometryCollection +{ + getArea(): number; + unionCascaded(): Geometry; +} + +export class Point extends Geometry +{ + constructor(x: number, y: number, z?: number); + + x: number; + y: number; + z: number; +} + +export class Polygon extends Geometry +{ + getArea(): number; + + rings: PolygonRings; +} + +export interface PolygonRings +{ + add(ring: LinearRing | LinearRing[]): void; + count(): number; + forEach(callback: (ring: LinearRing, i: number) => void): void; + get(index: number): LinearRing; + map(callback: (ring: LinearRing, i: number) => T): T[]; + remove(index: number): void; + toArray(): LinearRing[]; + + readonly layer: Layer; +} + +export interface RasterBand +{ + computeStatistics(allow_approximation: boolean): RasterBandStatistics; + createMaskBand(flags: number): void; + fill(real_value: number, imaginary_value?: number): void; + flush(): void; + getMaskBand(): RasterBand; + getMaskFlags(): number; + getMetadata(domain?: string): object; + getStatistics(allow_approximation: boolean, force: boolean): RasterBandStatistics; + setStatistics(min: number, max: number, mean: number, std_dev: number): void; + + readonly blockSize: XY; + categoryNames: string[]; + colorInterpretation: string; + readonly dataType: string; + readonly description: string; + readonly ds: Dataset; + readonly hasArbitraryOverviews: boolean; + readonly id: number; + readonly maximum: number; + readonly minimum: number; + noDataValue: number; + offset: number; + readonly overviews: RasterBandOverviews; + readonly pixels: RasterBandPixels; + readonly readOnly: boolean; + scale: number; + readonly size: XY; + unitType: string; +} + +export interface RasterBandOverviews +{ + count(): number; + forEach(callback: (overviewBand: RasterBand, i: number) => void): void; + get(index: number): RasterBand; + getBySampleCount(samples: number): RasterBand; + map(callback: (overviewBand: RasterBand, i: number) => T): T[]; +} + +export interface RasterBandPixels +{ + get(x: number, y: number): number; + read(x: number, y: number, width: number, height: number, data?: TypedArray, options?: RasterBandPixelsReadOptions): TypedArray; + readBlock(x: number, y: number, data?: TypedArray): TypedArray; + set(x: number, y: number, value: number): void; + write(x: number, y: number, width: number, height: number, data: TypedArray, options?: RasterBandPixelsWriteOptions): void; + writeBlock(x: number, y: number, data: TypedArray): void; +} + +export class SpatialReference +{ + constructor(wkt?: string); + autoIdentifyEPSG(): void; + clone(): SpatialReference; + cloneGeogCS(): SpatialReference; + EPSGTreatsAsLatLong(): boolean; + EPSGTreatsAsNorthingEasting(): boolean; + getAngularUnits(): { value: any, unit: any }; + getAttrValue(node_name: string, attr_index?: number): string; + getAuthorityCode(target_key: string): string; + getAuthorityName(target_key: string): string; + getLinearUnits(): { value: any, unit: any }; + isCompound(): boolean; + isGeocentric(): boolean; + isGeographic(): boolean; + isLocal(): boolean; + isProjected(): boolean; + isSame(srs: SpatialReference): boolean; + isSameGeogCS(srs: SpatialReference): boolean; + isSameVertCS(srs: SpatialReference): boolean; + isVertical(): boolean; + morphFromESRI(): void; + morphToESRI(): void; + setWellKnownGeogCS(name: string): void; + toPrettyWKT(simplify?: boolean): string; + toProj4(): string; + toWKT(): string; + toXML(): string; + validate(): string; + + static fromCRSURL(input: string): SpatialReference; + static fromEPSG(input: string): SpatialReference; + static fromEPSGA(input: number): SpatialReference; + static fromESRI(input: string[]): SpatialReference; + static fromMICoordSys(input: string): SpatialReference; + static fromProj4(input: string): SpatialReference; + static fromURL(url: string): SpatialReference; + static fromURN(input: string): SpatialReference; + static fromUserInput(input: string): SpatialReference; + static fromWKT(wkt: string): SpatialReference; + static fromWMSAUTO(input: string): SpatialReference; + static fromXML(input: string): SpatialReference; +} + +export namespace config +{ + function get(key: string): string; + function set(key: string, value: string): void; +} + +export const drivers: GDALDrivers; +export const lastError: { number: any, message: any, type: any }; +export const version: string; + +export function checksumImage(src: RasterBand, x?: number, y?: number, w?: number, h?: number): number; +export function contourGenerate(options: ContourGenerateOptions): void; +export function decToDMS(angle: number, axis: 'lat' | 'long', precision?: number): string; +export function fillNodata(options: FillNoDataOptions): void; +export function open(path: string, mode?: 'r' | 'r+' | 'w', drivers?: string | string[], x_size?: number, y_size?: number, band_count?: number, data_type?: number, creation_options?: string[] | object): Dataset; +export function polygonize(options: PolygonizeOptions): void; +export function quiet(): void; +export function reprojectImage(options: ReprojectImageOptions): void; +export function sieveFilter(options: SieveFilterOptions): void; +export function suggestedWarpOutput(options: SuggestedWarpOutputOptions): { rasterSize: any, geoTransform: any }; +export function verbose(): void; \ No newline at end of file diff --git a/types/gdal/tsconfig.json b/types/gdal/tsconfig.json new file mode 100644 index 0000000000..a7bd1cf386 --- /dev/null +++ b/types/gdal/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gdal-tests.ts" + ] +} diff --git a/types/gdal/tslint.json b/types/gdal/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gdal/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From cf4ed80a0837167bd53fdb9d23321fac19468efc Mon Sep 17 00:00:00 2001 From: NN Date: Tue, 27 Nov 2018 17:58:48 +0200 Subject: [PATCH 140/792] Fix #30848 configHash can be a string in HardSourceWebpackPlugin --- types/hard-source-webpack-plugin/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/hard-source-webpack-plugin/index.d.ts b/types/hard-source-webpack-plugin/index.d.ts index 3e02ee1d8a..4a83b58034 100644 --- a/types/hard-source-webpack-plugin/index.d.ts +++ b/types/hard-source-webpack-plugin/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for hard-source-webpack-plugin 0.9 +// Type definitions for hard-source-webpack-plugin 1.0 // Project: https://github.com/mzgoddard/hard-source-webpack-plugin#readme // Definitions by: woitechen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -15,7 +15,7 @@ declare namespace hard_source_webpack_plugin { } interface Options { cacheDirectory?: string; - configHash?: (webpackConfig?: webpack.Configuration) => string; + configHash?: string | ((webpackConfig?: webpack.Configuration) => string); environmentHash?: { root: string; directories: string[]; From a104ee185677834365ba69b74bd14cd14723d5e7 Mon Sep 17 00:00:00 2001 From: andreidigori <45198612+andreidigori@users.noreply.github.com> Date: Tue, 27 Nov 2018 19:05:34 +0200 Subject: [PATCH 141/792] Update tsconfig.json Set "strictFunctionTypes": false, --- types/gdal/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/gdal/tsconfig.json b/types/gdal/tsconfig.json index a7bd1cf386..3a5bfaf917 100644 --- a/types/gdal/tsconfig.json +++ b/types/gdal/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": false, "baseUrl": "../", "typeRoots": [ "../" From 08b098667ad9ab2e6ff405662be41b947af7e04f Mon Sep 17 00:00:00 2001 From: andreidigori <45198612+andreidigori@users.noreply.github.com> Date: Tue, 27 Nov 2018 19:20:57 +0200 Subject: [PATCH 142/792] Update index.d.ts TsLint check --- types/gdal/index.d.ts | 138 ++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 92 deletions(-) diff --git a/types/gdal/index.d.ts b/types/gdal/index.d.ts index 50280cff3d..41a89ff72f 100644 --- a/types/gdal/index.d.ts +++ b/types/gdal/index.d.ts @@ -11,49 +11,42 @@ export as namespace gdal; export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; export type Resampling = 'NEAREST' | 'GAUSS' | 'CUBIC' | 'AVERAGE' | 'MODE' | 'AVERAGE_MAGPHASE' | 'NONE'; -export interface XY -{ +export interface XY { x: number; y: number; } -export interface XYZ extends XY -{ +export interface XYZ extends XY { z: number; } -export interface EnvelopeBounds -{ +export interface EnvelopeBounds { minX: number, maxX: number, minY: number, maxY: number } -export interface Envelope3DBounds extends EnvelopeBounds -{ +export interface Envelope3DBounds extends EnvelopeBounds { minZ: number, maxZ: number } -export interface RasterBandStatistics -{ +export interface RasterBandStatistics { min: number; max: number; mean: number; std_dev: number; } -export interface RasterBandPixelsWriteOptions -{ +export interface RasterBandPixelsWriteOptions { buffer_width?: number; buffer_height?: number; pixel_space?: number; line_space?: number; } -export interface RasterBandPixelsReadOptions -{ +export interface RasterBandPixelsReadOptions { buffer_width?: number; buffer_height?: number; pixel_space?: number; @@ -61,8 +54,7 @@ export interface RasterBandPixelsReadOptions data_type?: string; } -export interface ContourGenerateOptions -{ +export interface ContourGenerateOptions { src: RasterBand; dst: Layer; offset?: number; @@ -73,16 +65,14 @@ export interface ContourGenerateOptions elevField?: number; } -export interface FillNoDataOptions -{ +export interface FillNoDataOptions { src: RasterBand; mask?: RasterBand; searchDist: number; smoothingIterations?: number; } -export interface PolygonizeOptions -{ +export interface PolygonizeOptions { src: RasterBand; dst: Layer; mask?: RasterBand; @@ -91,8 +81,7 @@ export interface PolygonizeOptions useFloats?: boolean; } -export interface ReprojectImageOptions -{ +export interface ReprojectImageOptions { src: Dataset; dst: Dataset; s_srs: SpatialReference; @@ -111,8 +100,7 @@ export interface ReprojectImageOptions options?: string[] | object; } -export interface SieveFilterOptions -{ +export interface SieveFilterOptions { src: RasterBand; dst: RasterBand; mask?: RasterBand; @@ -120,8 +108,7 @@ export interface SieveFilterOptions connectedness?: number; } -export interface SuggestedWarpOutputOptions -{ +export interface SuggestedWarpOutputOptions { src: Dataset; s_srs: SpatialReference; t_srs: SpatialReference; @@ -283,14 +270,12 @@ export const wkbVariantOldOgc: string; /* Classes and interfaces */ -export class CoordinateTransformation -{ +export class CoordinateTransformation { constructor(source: SpatialReference, target: SpatialReference | Dataset); transformPoint(x: number, y: number, z?: number): XYZ; } -export interface Dataset -{ +export interface Dataset { buildOverviews(resampling: Resampling, overviews: number[], bands?: number[]): void; close(): void; executeSQL(statement: string, spatial_filter?: Geometry, dialect?: string): Layer; @@ -311,8 +296,7 @@ export interface Dataset srs: SpatialReference; } -export interface DatasetBands -{ +export interface DatasetBands { count(): number; create(dataType: number): RasterBand; forEach(callback: (band: RasterBand, i: number) => void): void; @@ -322,8 +306,7 @@ export interface DatasetBands readonly ds: Dataset; } -export interface DatasetLayers -{ +export interface DatasetLayers { copy(src_lyr_name: string, dst_lyr_name: string, options?: object | string[]): Layer; count(): number; create(name: string, srs: SpatialReference, geomType: number | Function, creation_options: string[] | object): Layer; @@ -335,8 +318,7 @@ export interface DatasetLayers readonly ds: Dataset; } -export interface Driver -{ +export interface Driver { copyFiles(name_old: string, name_new: string): void; create(filename: string, x_size?: number, y_size?: number, band_count?: number, data_type?: number, creation_options?: string[] | object): Dataset; createCopy(filename: string, src: Dataset, strict?: boolean, options?: string[] | object): Dataset; @@ -348,8 +330,7 @@ export interface Driver readonly description: string; } -export class Envelope -{ +export class Envelope { constructor(bounds: EnvelopeBounds); contains(envelope: Envelope): boolean; intersect(envelope: Envelope): void; @@ -359,13 +340,11 @@ export class Envelope toPolygon(): Polygon; } -export class Envelope3D extends Envelope -{ +export class Envelope3D extends Envelope { constructor(bounds: Envelope3DBounds); } -export class Feature -{ +export class Feature { constructor(definition: Layer | FeatureDefn); clone(): Feature; destroy(): void; @@ -380,8 +359,7 @@ export class Feature readonly fields: FeatureFields; } -export class FeatureDefn -{ +export class FeatureDefn { constructor(); clone(): FeatureDefn; @@ -392,8 +370,7 @@ export class FeatureDefn styleIgnored: boolean; } -export interface FeatureDefnFields -{ +export interface FeatureDefnFields { add(field: FieldDefn | FieldDefn[]): void; count(): number; forEach(callback: (field: FieldDefn, i: number) => void): void; @@ -407,8 +384,7 @@ export interface FeatureDefnFields readonly featureDefn: FeatureDefn; } -export interface FeatureFields -{ +export interface FeatureFields { count(): number; forEach(callback: (value: any, key: string) => void): void; get(key: string | number): any; @@ -424,8 +400,7 @@ export interface FeatureFields readonly feature: Feature; } -export class FieldDefn -{ +export class FieldDefn { constructor(name: string, type: string); ignored: boolean; @@ -436,8 +411,7 @@ export class FieldDefn width: number; } -export interface GDALDrivers -{ +export interface GDALDrivers { count(): number; forEach(callback: (driver: Driver, i: number) => void): void; get(index: number | string): Driver; @@ -445,8 +419,7 @@ export interface GDALDrivers map(callback: (driver: Driver, i: number) => T): T[]; } -export abstract class Geometry -{ +export abstract class Geometry { static create(type: number): Geometry; static fromWKB(wkb: number, srs?: SpatialReference): Geometry; static fromWKT(wkt: string, srs?: SpatialReference): Geometry; @@ -500,16 +473,14 @@ export abstract class Geometry readonly wkbType: number; } -export class GeometryCollection extends Geometry -{ +export class GeometryCollection extends Geometry { getArea(): number; getLength(): number; children: GeometryCollectionChildren; } -export interface GeometryCollectionChildren -{ +export interface GeometryCollectionChildren { add(geometry: Geometry | Geometry[]): void; count(): number; forEach(callback: (geometry: Geometry, i: number) => void): void; @@ -521,8 +492,7 @@ export interface GeometryCollectionChildren readonly layer: Layer; } -export interface Layer -{ +export interface Layer { flush(): void; getExtent(force?: boolean): Envelope; getSpatialFilter(): Geometry; @@ -541,8 +511,7 @@ export interface Layer readonly srs: SpatialReference; } -export interface LayerFeatures -{ +export interface LayerFeatures { add(feature: Feature): void; count(force?: boolean): number; first(): Feature; @@ -556,8 +525,7 @@ export interface LayerFeatures readonly layer: Layer; } -export interface LayerFields -{ +export interface LayerFields { add(def: FieldDefn | FieldDefn[], approx?: boolean): void; count(): number; forEach(callback: (field: FieldDefn, i: number) => void): void; @@ -572,13 +540,11 @@ export interface LayerFields readonly layer: Layer; } -export class LinearRing extends LineString -{ +export class LinearRing extends LineString { getArea(): number; } -export class LineString extends Geometry -{ +export class LineString extends Geometry { addSubLineString(line: LineString, start?: number, end?: number): void; getLength(): number; value(distance: number): Point; @@ -586,8 +552,7 @@ export class LineString extends Geometry readonly points: LineStringPoints; } -export interface LineStringPoints -{ +export interface LineStringPoints { add(point: Point | Point[]): void; count(): number; forEach(callback: (point: Point, i: number) => void): void; @@ -600,24 +565,20 @@ export interface LineStringPoints toArray(): Point[]; } -export class MultiLineString extends GeometryCollection -{ +export class MultiLineString extends GeometryCollection { polygonize(): Polygon; } -export class MultiPoint extends GeometryCollection -{ +export class MultiPoint extends GeometryCollection { } -export class MultiPolygon extends GeometryCollection -{ +export class MultiPolygon extends GeometryCollection { getArea(): number; unionCascaded(): Geometry; } -export class Point extends Geometry -{ +export class Point extends Geometry { constructor(x: number, y: number, z?: number); x: number; @@ -625,15 +586,13 @@ export class Point extends Geometry z: number; } -export class Polygon extends Geometry -{ +export class Polygon extends Geometry { getArea(): number; rings: PolygonRings; } -export interface PolygonRings -{ +export interface PolygonRings { add(ring: LinearRing | LinearRing[]): void; count(): number; forEach(callback: (ring: LinearRing, i: number) => void): void; @@ -645,8 +604,7 @@ export interface PolygonRings readonly layer: Layer; } -export interface RasterBand -{ +export interface RasterBand { computeStatistics(allow_approximation: boolean): RasterBandStatistics; createMaskBand(flags: number): void; fill(real_value: number, imaginary_value?: number): void; @@ -677,8 +635,7 @@ export interface RasterBand unitType: string; } -export interface RasterBandOverviews -{ +export interface RasterBandOverviews { count(): number; forEach(callback: (overviewBand: RasterBand, i: number) => void): void; get(index: number): RasterBand; @@ -686,8 +643,7 @@ export interface RasterBandOverviews map(callback: (overviewBand: RasterBand, i: number) => T): T[]; } -export interface RasterBandPixels -{ +export interface RasterBandPixels { get(x: number, y: number): number; read(x: number, y: number, width: number, height: number, data?: TypedArray, options?: RasterBandPixelsReadOptions): TypedArray; readBlock(x: number, y: number, data?: TypedArray): TypedArray; @@ -696,8 +652,7 @@ export interface RasterBandPixels writeBlock(x: number, y: number, data: TypedArray): void; } -export class SpatialReference -{ +export class SpatialReference { constructor(wkt?: string); autoIdentifyEPSG(): void; clone(): SpatialReference; @@ -741,8 +696,7 @@ export class SpatialReference static fromXML(input: string): SpatialReference; } -export namespace config -{ +export namespace config { function get(key: string): string; function set(key: string, value: string): void; } From 2de6fbab6151900dba10d85f9a6268ac13a88d1b Mon Sep 17 00:00:00 2001 From: huan086 Date: Tue, 27 Nov 2018 14:37:15 +0800 Subject: [PATCH 143/792] [radix64] Add Typescript definitions. --- types/radix64/index.d.ts | 23 +++++++++++++++++++++++ types/radix64/radix64-tests.ts | 11 +++++++++++ types/radix64/tsconfig.json | 23 +++++++++++++++++++++++ types/radix64/tslint.json | 1 + 4 files changed, 58 insertions(+) create mode 100644 types/radix64/index.d.ts create mode 100644 types/radix64/radix64-tests.ts create mode 100644 types/radix64/tsconfig.json create mode 100644 types/radix64/tslint.json diff --git a/types/radix64/index.d.ts b/types/radix64/index.d.ts new file mode 100644 index 0000000000..f376184fce --- /dev/null +++ b/types/radix64/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for radix64 1.1 +// Project: https://github.com/maxired/radix64 +// Definitions by: Jeow Li Huan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type MethodsString = 'base64' | 'base64URL' | 'base64URLNaturalSort' | 'base64URLASCIISort'; + +interface MethodsEnum { + BASE64: MethodsString; + BASE64URL: MethodsString; + BASE64NATURAL: MethodsString; + BASE64ASCII: MethodsString; + DEFAULT: MethodsString; +} + +interface Radix { + radix64: (number: number, method?: MethodsString) => string; + ascii64: (number: number, pad?: number) => string; + methods: MethodsEnum; +} + +declare const radix: Radix; +export = radix; diff --git a/types/radix64/radix64-tests.ts b/types/radix64/radix64-tests.ts new file mode 100644 index 0000000000..a77554c238 --- /dev/null +++ b/types/radix64/radix64-tests.ts @@ -0,0 +1,11 @@ +import radix64 = require("radix64"); + +const num: string = radix64.radix64(42); + +const numAndEnum: string = radix64.radix64(1337, radix64.methods.BASE64NATURAL); + +const numAndString: string = radix64.radix64(1337, 'base64URL'); + +const asciiNum: string = radix64.ascii64(42); + +const asciiNumAndPad: string = radix64.ascii64(42, 25); diff --git a/types/radix64/tsconfig.json b/types/radix64/tsconfig.json new file mode 100644 index 0000000000..362ad6d26e --- /dev/null +++ b/types/radix64/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "radix64-tests.ts" + ] +} diff --git a/types/radix64/tslint.json b/types/radix64/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/radix64/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From acd8209e0673bf6e558e8342706c7b5809b9e7c5 Mon Sep 17 00:00:00 2001 From: andreidigori <45198612+andreidigori@users.noreply.github.com> Date: Tue, 27 Nov 2018 19:29:25 +0200 Subject: [PATCH 144/792] Update index.d.ts Linting --- types/gdal/index.d.ts | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/types/gdal/index.d.ts b/types/gdal/index.d.ts index 41a89ff72f..6aca0120de 100644 --- a/types/gdal/index.d.ts +++ b/types/gdal/index.d.ts @@ -21,15 +21,15 @@ export interface XYZ extends XY { } export interface EnvelopeBounds { - minX: number, - maxX: number, - minY: number, - maxY: number + minX: number; + maxX: number; + minY: number; + maxY: number; } export interface Envelope3DBounds extends EnvelopeBounds { - minZ: number, - maxZ: number + minZ: number; + maxZ: number; } export interface RasterBandStatistics { @@ -309,7 +309,7 @@ export interface DatasetBands { export interface DatasetLayers { copy(src_lyr_name: string, dst_lyr_name: string, options?: object | string[]): Layer; count(): number; - create(name: string, srs: SpatialReference, geomType: number | Function, creation_options: string[] | object): Layer; + create(name: string, srs: SpatialReference, geomType: number | Geometry, creation_options: string[] | object): Layer; forEach(callback: (layer: Layer, i: number) => void): void; get(key: string | number): Layer; map(callback: (layer: Layer, i: number) => T): T[]; @@ -423,7 +423,7 @@ export abstract class Geometry { static create(type: number): Geometry; static fromWKB(wkb: number, srs?: SpatialReference): Geometry; static fromWKT(wkt: string, srs?: SpatialReference): Geometry; - static getConstructor(type: number): Function; + static getConstructor(type: number): Geometry; static getName(type: number): string; boundary(): Geometry; @@ -488,7 +488,6 @@ export interface GeometryCollectionChildren { map(callback: (geometry: Geometry, i: number) => T): T[]; remove(index: number): void; toArray(): Geometry[]; - readonly layer: Layer; } @@ -500,7 +499,6 @@ export interface Layer { setSpatialFilter(filter: Geometry): void; setSpatialFilter(minX: number, maxX: number, minY: number, maxY: number): void; testCapability(capability: string): boolean; - readonly ds: Dataset; readonly features: LayerFeatures; readonly fidColumn: string; @@ -521,7 +519,6 @@ export interface LayerFeatures { next(): Feature; remove(id: number): void; set(id: number, feature: Feature): void; - readonly layer: Layer; } @@ -536,7 +533,6 @@ export interface LayerFields { map(callback: (field: FieldDefn, i: number) => T): T[]; remove(field: string | number): void; reorder(map: number[]): void; - readonly layer: Layer; } @@ -548,7 +544,6 @@ export class LineString extends Geometry { addSubLineString(line: LineString, start?: number, end?: number): void; getLength(): number; value(distance: number): Point; - readonly points: LineStringPoints; } @@ -580,7 +575,6 @@ export class MultiPolygon extends GeometryCollection { export class Point extends Geometry { constructor(x: number, y: number, z?: number); - x: number; y: number; z: number; @@ -588,7 +582,6 @@ export class Point extends Geometry { export class Polygon extends Geometry { getArea(): number; - rings: PolygonRings; } @@ -600,7 +593,6 @@ export interface PolygonRings { map(callback: (ring: LinearRing, i: number) => T): T[]; remove(index: number): void; toArray(): LinearRing[]; - readonly layer: Layer; } @@ -614,7 +606,6 @@ export interface RasterBand { getMetadata(domain?: string): object; getStatistics(allow_approximation: boolean, force: boolean): RasterBandStatistics; setStatistics(min: number, max: number, mean: number, std_dev: number): void; - readonly blockSize: XY; categoryNames: string[]; colorInterpretation: string; @@ -681,7 +672,6 @@ export class SpatialReference { toWKT(): string; toXML(): string; validate(): string; - static fromCRSURL(input: string): SpatialReference; static fromEPSG(input: string): SpatialReference; static fromEPSGA(input: number): SpatialReference; @@ -709,10 +699,11 @@ export function checksumImage(src: RasterBand, x?: number, y?: number, w?: numbe export function contourGenerate(options: ContourGenerateOptions): void; export function decToDMS(angle: number, axis: 'lat' | 'long', precision?: number): string; export function fillNodata(options: FillNoDataOptions): void; -export function open(path: string, mode?: 'r' | 'r+' | 'w', drivers?: string | string[], x_size?: number, y_size?: number, band_count?: number, data_type?: number, creation_options?: string[] | object): Dataset; +export function open(path: string, mode?: 'r' | 'r+' | 'w', drivers?: string | string[]): Dataset; +export function open(path: string, mode?: 'w', drivers?: string | string[], x_size?: number, y_size?: number, band_count?: number, data_type?: number, creation_options?: string[] | object): Dataset; export function polygonize(options: PolygonizeOptions): void; export function quiet(): void; export function reprojectImage(options: ReprojectImageOptions): void; export function sieveFilter(options: SieveFilterOptions): void; export function suggestedWarpOutput(options: SuggestedWarpOutputOptions): { rasterSize: any, geoTransform: any }; -export function verbose(): void; \ No newline at end of file +export function verbose(): void; From 62f4c1c89c2c6fac264ac4ca7ffbf2c76c69974e Mon Sep 17 00:00:00 2001 From: huan086 Date: Tue, 27 Nov 2018 10:41:47 +0800 Subject: [PATCH 145/792] [preval.macro] Add Typescript definitions. --- types/preval.macro/index.d.ts | 7 +++++++ types/preval.macro/preval.macro-tests.ts | 5 +++++ types/preval.macro/tsconfig.json | 23 +++++++++++++++++++++++ types/preval.macro/tslint.json | 1 + 4 files changed, 36 insertions(+) create mode 100644 types/preval.macro/index.d.ts create mode 100644 types/preval.macro/preval.macro-tests.ts create mode 100644 types/preval.macro/tsconfig.json create mode 100644 types/preval.macro/tslint.json diff --git a/types/preval.macro/index.d.ts b/types/preval.macro/index.d.ts new file mode 100644 index 0000000000..4ecfa3bf25 --- /dev/null +++ b/types/preval.macro/index.d.ts @@ -0,0 +1,7 @@ +// Type definitions for preval.macro 3.0 +// Project: https://github.com/kentcdodds/preval.macro +// Definitions by: Jeow Li Huan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function preval(strings: TemplateStringsArray, ...values: any[]): any; +export = preval; diff --git a/types/preval.macro/preval.macro-tests.ts b/types/preval.macro/preval.macro-tests.ts new file mode 100644 index 0000000000..fc2f0aa409 --- /dev/null +++ b/types/preval.macro/preval.macro-tests.ts @@ -0,0 +1,5 @@ +import preval = require('preval.macro'); + +const eg1: string = preval`module.exports = 'hello world`; +const eg2: number = preval`module.exports = 42`; +const eg3: { [key: string]: string } = preval`module.exports = { hello: 'world' }`; diff --git a/types/preval.macro/tsconfig.json b/types/preval.macro/tsconfig.json new file mode 100644 index 0000000000..b895c306f0 --- /dev/null +++ b/types/preval.macro/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "preval.macro-tests.ts" + ] +} diff --git a/types/preval.macro/tslint.json b/types/preval.macro/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/preval.macro/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From d076418dc2fb9748a78bb49a4a585b577703d158 Mon Sep 17 00:00:00 2001 From: andreidigori <45198612+andreidigori@users.noreply.github.com> Date: Tue, 27 Nov 2018 19:33:23 +0200 Subject: [PATCH 146/792] Update index.d.ts Linting --- types/gdal/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/gdal/index.d.ts b/types/gdal/index.d.ts index 6aca0120de..d6c76ba226 100644 --- a/types/gdal/index.d.ts +++ b/types/gdal/index.d.ts @@ -564,9 +564,7 @@ export class MultiLineString extends GeometryCollection { polygonize(): Polygon; } -export class MultiPoint extends GeometryCollection { - -} +export class MultiPoint extends GeometryCollection {} export class MultiPolygon extends GeometryCollection { getArea(): number; From 289c533aadb4ee5d6a7ef2a740c4d38cd7b6cc59 Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Tue, 27 Nov 2018 17:27:21 +0000 Subject: [PATCH 147/792] [@babel/traverse]: Fixed type of path when using enter & exit visitor. --- types/babel__traverse/babel__traverse-tests.ts | 8 ++++++-- types/babel__traverse/index.d.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/types/babel__traverse/babel__traverse-tests.ts b/types/babel__traverse/babel__traverse-tests.ts index 5b4fbbef5f..974831dbca 100644 --- a/types/babel__traverse/babel__traverse-tests.ts +++ b/types/babel__traverse/babel__traverse-tests.ts @@ -4,10 +4,14 @@ import * as t from "@babel/types"; // Examples from: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md const MyVisitor: Visitor = { Identifier: { - enter() { + enter(path) { + // $ExpectType NodePath + path; console.log("Entered!"); }, - exit() { + exit(path) { + // $ExpectType NodePath + path; console.log("Exited!"); } } diff --git a/types/babel__traverse/index.d.ts b/types/babel__traverse/index.d.ts index 465a60464f..740f5f4429 100644 --- a/types/babel__traverse/index.d.ts +++ b/types/babel__traverse/index.d.ts @@ -142,7 +142,7 @@ export type Visitor = VisitNodeObject & { [P in Node["type"]]?: VisitNode>; }; -export type VisitNode = VisitNodeFunction | VisitNodeObject; +export type VisitNode = VisitNodeFunction | VisitNodeObject

; export type VisitNodeFunction = (this: T, path: NodePath

, state: any) => void; From de00f487a807ae96036e82b11a60c187f62a12ec Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Tue, 27 Nov 2018 19:09:57 +0100 Subject: [PATCH 148/792] [microservice-utilities] Add a type for flat object with string for the header object in PlatformClient --- types/microservice-utilities/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/microservice-utilities/index.d.ts b/types/microservice-utilities/index.d.ts index e8ccb9284e..7b2c4be923 100644 --- a/types/microservice-utilities/index.d.ts +++ b/types/microservice-utilities/index.d.ts @@ -42,13 +42,13 @@ export interface PlatformClientResponse { export class PlatformClient { constructor(logFunction: (msg: any) => void, tokenResolverFunction?: Promise<() => string>, configuration?: PlatformClientConfiguration) - get(url: string, headers?: object, type?: string): Promise; - post(url: string, data: object, headers?: object): Promise; - put(url: string, data: object, headers?: object): Promise; - patch(url: string, data: object, headers?: object): Promise; - delete(url: string, headers?: object): Promise; - head(url: string, headers?: object): Promise; - options(url: string, headers?: object): Promise; + get(url: string, headers?: { [s: string]: string; }, type?: string): Promise; + post(url: string, data: object, headers?: { [s: string]: string; }): Promise; + put(url: string, data: object, headers?: { [s: string]: string; }): Promise; + patch(url: string, data: object, headers?: { [s: string]: string; }): Promise; + delete(url: string, headers?: { [s: string]: string; }): Promise; + head(url: string, headers?: { [s: string]: string; }): Promise; + options(url: string, headers?: { [s: string]: string; }): Promise; } /** From f757203084ed5793a80255c032740738d0a82c86 Mon Sep 17 00:00:00 2001 From: Jake Boone Date: Tue, 27 Nov 2018 11:44:14 -0700 Subject: [PATCH 149/792] [react-datepicker] v2.0.0 --- types/react-datepicker/index.d.ts | 69 ++++++++++++++++++----------- types/react-datepicker/package.json | 1 - 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/types/react-datepicker/index.d.ts b/types/react-datepicker/index.d.ts index 23e542d322..6368e273e3 100644 --- a/types/react-datepicker/index.d.ts +++ b/types/react-datepicker/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-datepicker 1.1 +// Type definitions for react-datepicker 2.0 // Project: https://github.com/Hacker0x01/react-datepicker // Definitions by: Rajab Shakirov , // Andrey Balokha , @@ -7,11 +7,11 @@ // Roy Xue // Koala Human // Sean Kelley +// Jake Boone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as React from "react"; -import * as moment from "moment"; import * as Popper from "popper.js"; export interface ReactDatePickerProps { @@ -20,59 +20,65 @@ export interface ReactDatePickerProps { autoComplete?: string; autoFocus?: boolean; calendarClassName?: string; + calendarContainer?(props: { children: React.ReactNode[] }): React.ReactNode; children?: React.ReactNode; className?: string; customInput?: React.ReactNode; customInputRef?: string; dateFormat?: string | string[]; dateFormatCalendar?: string; - dayClassName?(date: moment.Moment): string | null; + dayClassName?(date: Date): string | null; disabled?: boolean; disabledKeyboardNavigation?: boolean; dropdownMode?: 'scroll' | 'select'; - endDate?: moment.Moment; - excludeDates?: moment.Moment[]; - excludeTimes?: moment.Moment[]; - filterDate?(date: moment.Moment): boolean; + endDate?: Date; + excludeDates?: Date[]; + excludeTimes?: Date[]; + filterDate?(date: Date): boolean; fixedHeight?: boolean; forceShowMonthNavigation?: boolean; - formatWeekNumber?(date: moment.Moment): string | number; - highlightDates?: moment.Moment[]; + formatWeekNumber?(date: Date): string | number; + highlightDates?: Date[]; id?: string; - includeDates?: moment.Moment[]; - includeTimes?: moment.Moment[]; + includeDates?: Date[]; + includeTimes?: Date[]; + injectTimes?: Date[]; inline?: boolean; isClearable?: boolean; locale?: string; - maxDate?: moment.Moment; - maxTime?: moment.Moment; - minDate?: moment.Moment; - minTime?: moment.Moment; + maxDate?: Date; + maxTime?: Date; + minDate?: Date; + minTime?: Date; monthsShown?: number; name?: string; onBlur?(event: React.FocusEvent): void; - onChange(date: moment.Moment | null, event: React.SyntheticEvent | undefined): void; + onChange(date: Date | null, event: React.SyntheticEvent | undefined): void; onChangeRaw?(event: React.FocusEvent): void; onClickOutside?(event: React.MouseEvent): void; onFocus?(event: React.FocusEvent): void; onKeyDown?(event: React.KeyboardEvent): void; - onMonthChange?(date: moment.Moment): void; - onSelect?(date: moment.Moment, event: React.SyntheticEvent | undefined): void; - onWeekSelect?(firstDayOfWeek: moment.Moment, weekNumber: string | number, event: React.SyntheticEvent | undefined): void; - onYearChange?(date: moment.Moment): void; - openToDate?: moment.Moment; + onMonthChange?(date: Date): void; + onSelect?(date: Date, event: React.SyntheticEvent | undefined): void; + onWeekSelect?(firstDayOfWeek: Date, weekNumber: string | number, event: React.SyntheticEvent | undefined): void; + onInputClick?(): void; + onYearChange?(date: Date): void; + onInputError?(err: {code: number; msg: string}): void; + open?: boolean; + openToDate?: Date; peekNextMonth?: boolean; placeholderText?: string; popperClassName?: string; popperContainer?(props: { children: React.ReactNode[] }): React.ReactNode; popperModifiers?: Popper.Modifiers; popperPlacement?: string; + popperProps?: {}; preventOpenOnFocus?: boolean; readOnly?: boolean; required?: boolean; scrollableMonthYearDropdown?: boolean; scrollableYearDropdown?: boolean; - selected?: moment.Moment | null; + selected?: Date | null; selectsEnd?: boolean; selectsStart?: boolean; shouldCloseOnSelect?: boolean; @@ -83,21 +89,34 @@ export interface ReactDatePickerProps { showTimeSelectOnly?: boolean; showWeekNumbers?: boolean; showYearDropdown?: boolean; - startDate?: moment.Moment; + startDate?: Date; startOpen?: boolean; tabIndex?: number; timeCaption?: string; timeFormat?: string; timeIntervals?: number; title?: string; - todayButton?: string; + todayButton?: React.ReactNode; useShortMonthInDropdown?: boolean; useWeekdaysShort?: boolean; - utcOffset?: number; value?: string; weekLabel?: string; withPortal?: boolean; yearDropdownItemNumber?: number; + formatWeekDay?(date: Date): string; + clearButtonTitle?: string; + previousMonthButtonLabel?: string; + nextMonthButtonLabel?: string; + renderCustomHeader?(params: { + date: Date; + changeYear(year: number): void; + changeMonth(month: number): void; + decreaseMonth(): void; + increaseMonth(): void; + prevMonthButtonDisabled: boolean; + nextMonthButtonDisabled: boolean; + }): React.ReactNode; + renderDayContents?(dayOfMonth: number): React.ReactNode; } declare const ReactDatePicker: React.ClassicComponentClass; export default ReactDatePicker; diff --git a/types/react-datepicker/package.json b/types/react-datepicker/package.json index fc763e4d4b..245f69cd2c 100644 --- a/types/react-datepicker/package.json +++ b/types/react-datepicker/package.json @@ -1,7 +1,6 @@ { "private": true, "dependencies": { - "moment": ">=2.14.0", "popper.js": "^1.14.1" } } From c3f0ee0d5d9765ac9fe65da8c75e477a71e398ca Mon Sep 17 00:00:00 2001 From: Jake Boone Date: Tue, 27 Nov 2018 11:55:08 -0700 Subject: [PATCH 150/792] [react-datepicker] fix v2 tests --- types/react-datepicker/react-datepicker-tests.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/types/react-datepicker/react-datepicker-tests.tsx b/types/react-datepicker/react-datepicker-tests.tsx index 1414672684..4a3fd93cac 100644 --- a/types/react-datepicker/react-datepicker-tests.tsx +++ b/types/react-datepicker/react-datepicker-tests.tsx @@ -1,17 +1,16 @@ import * as React from 'react'; -import * as moment from 'moment'; import DatePicker from 'react-datepicker'; {}} - onYearChange={(date: moment.Moment) => {}} + selected={new Date()} + onChange={(date: Date | null) => {}} + onYearChange={(date: Date) => {}} popperModifiers={{ flip: { enabled: false } }} - includeTimes={[moment()]} + includeTimes={[new Date()]} >

From 0226045de5e8db79594af54dbab3f5b77b972d3c Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Tue, 27 Nov 2018 20:42:30 +0000 Subject: [PATCH 151/792] Implemented all changes outlined in the comments in pull request #30862. --- .../babel__traverse/babel__traverse-tests.ts | 37 +++++++++++++++++++ types/babel__traverse/index.d.ts | 14 +++---- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/types/babel__traverse/babel__traverse-tests.ts b/types/babel__traverse/babel__traverse-tests.ts index 974831dbca..772b392b63 100644 --- a/types/babel__traverse/babel__traverse-tests.ts +++ b/types/babel__traverse/babel__traverse-tests.ts @@ -112,3 +112,40 @@ const BindingKindTest: Visitor = { // kind === 'anythingElse'; }, }; + +interface SomeVisitorState { someState: string; } + +const VisitorStateTest: Visitor = { + enter(path, state) { + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + exit(path, state) { + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + Identifier(path, state) { + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + FunctionDeclaration: { + enter(path, state) { + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + exit(path, state) { + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + } + } +}; diff --git a/types/babel__traverse/index.d.ts b/types/babel__traverse/index.d.ts index 740f5f4429..a0a3730057 100644 --- a/types/babel__traverse/index.d.ts +++ b/types/babel__traverse/index.d.ts @@ -138,17 +138,17 @@ export class Binding { constantViolations: NodePath[]; } -export type Visitor = VisitNodeObject & { - [P in Node["type"]]?: VisitNode>; +export type Visitor = VisitNodeObject & { + [Type in Node["type"]]?: VisitNode>; }; -export type VisitNode = VisitNodeFunction | VisitNodeObject

; +export type VisitNode = VisitNodeFunction | VisitNodeObject; -export type VisitNodeFunction = (this: T, path: NodePath

, state: any) => void; +export type VisitNodeFunction = (this: S, path: NodePath

, state: S) => void; -export interface VisitNodeObject { - enter?(path: NodePath, state: any): void; - exit?(path: NodePath, state: any): void; +export interface VisitNodeObject { + enter?: VisitNodeFunction; + exit?: VisitNodeFunction; } export class NodePath { From 00f1245e599f463b2ea16b4e77e85bf73f9cbca5 Mon Sep 17 00:00:00 2001 From: piotr rotynski Date: Tue, 27 Nov 2018 23:22:07 +0100 Subject: [PATCH 152/792] Adding withArgs method to Spy interface as per Jasmine's docs for v3.3 --- types/jasmine/index.d.ts | 1 + types/jasmine/jasmine-tests.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index e9dba1e2cd..a87b8b3a86 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -639,6 +639,7 @@ declare namespace jasmine { calls: Calls; mostRecentCall: { args: any[]; }; argsForCall: any[]; + withArgs(...args: any[]): Spy; } type SpyObj = T & { diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index ba8763ce3d..92f9a21db8 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -469,6 +469,40 @@ describe("A spy, when configured with an alternate implementation", () => { }); }); +describe("A spy, when configured with alternate implementations for specified arguments", () => { + var foo: any, bar: any, fetchedBar: any; + + beforeEach(() => { + foo = { + setBar: (value: any) => { + bar = value; + }, + getBar: () => { + return bar; + } + }; + + spyOn(foo, "getBar") + .withArgs(1, "2") + .and.callFake(() => 1002); + + foo.setBar(123); + fetchedBar = foo.getBar(1, "2"); + }); + + it("tracks that the spy was called", () => { + expect(foo.getBar).toHaveBeenCalled(); + }); + + it("should not effect other functions", () => { + expect(bar).toEqual(123); + }); + + it("when called returns the requested value", () => { + expect(fetchedBar).toEqual(1002); + }); +}); + describe("A spy, when configured to throw a value", () => { var foo: any, bar: any; From c63de7c41921667f3bc0723d6206c78bae4ae230 Mon Sep 17 00:00:00 2001 From: timhwang21 Date: Tue, 27 Nov 2018 18:03:50 -0500 Subject: [PATCH 153/792] [bip39] Add Buffer as valid argument for entropyToMnemonic The function accepts either string or buffer. --- types/bip39/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/bip39/index.d.ts b/types/bip39/index.d.ts index a5d58cf961..6894ac3b30 100644 --- a/types/bip39/index.d.ts +++ b/types/bip39/index.d.ts @@ -17,7 +17,7 @@ export const wordlists: { spanish: string[]; }; -export function entropyToMnemonic(entropyHex: string, wordlist?: string[]): string; +export function entropyToMnemonic(entropyHex: Buffer | string, wordlist?: string[]): string; export function generateMnemonic(strength?: number, rng?: (size: number) => Buffer, wordlist?: string[]): string; From 53771da91e57c816f8f1899c2e4e072a9bcf97f8 Mon Sep 17 00:00:00 2001 From: Chris Arnesen Date: Wed, 28 Nov 2018 14:15:24 +0700 Subject: [PATCH 154/792] Add options arg to "find-versions" --- types/find-versions/find-versions-tests.ts | 3 ++- types/find-versions/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/find-versions/find-versions-tests.ts b/types/find-versions/find-versions-tests.ts index 81ea6ca974..e92e6d9848 100644 --- a/types/find-versions/find-versions-tests.ts +++ b/types/find-versions/find-versions-tests.ts @@ -1,3 +1,4 @@ import findVersions = require('find-versions'); -findVersions('node v1.0.0'); +findVersions('node v1.0.0'); // $ExpectType string[] +findVersions('1.0', { loose: true }); // $ExpectType string[] diff --git a/types/find-versions/index.d.ts b/types/find-versions/index.d.ts index 449c5a45c3..f22e3796e2 100644 --- a/types/find-versions/index.d.ts +++ b/types/find-versions/index.d.ts @@ -3,5 +3,5 @@ // Definitions by: Leonid Logvinov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare function findVersions(version: string): string[]; +declare function findVersions(version: string, options?: { loose: boolean }): string[]; export = findVersions; From 95b52bea5276fb948958f3d8e4929954b27fd39c Mon Sep 17 00:00:00 2001 From: Chris Arnesen Date: Wed, 28 Nov 2018 14:22:42 +0700 Subject: [PATCH 155/792] Update metadata --- types/find-versions/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/find-versions/index.d.ts b/types/find-versions/index.d.ts index f22e3796e2..7151227fb2 100644 --- a/types/find-versions/index.d.ts +++ b/types/find-versions/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for find-versions 2.0 +// Type definitions for find-versions 3.0 // Project: https://github.com/sindresorhus/find-versions // Definitions by: Leonid Logvinov +// Chris Arnesen Date: Wed, 28 Nov 2018 15:29:38 +0700 Subject: [PATCH 156/792] Update types/find-versions/index.d.ts --- types/find-versions/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/find-versions/index.d.ts b/types/find-versions/index.d.ts index 7151227fb2..9531c1628f 100644 --- a/types/find-versions/index.d.ts +++ b/types/find-versions/index.d.ts @@ -1,7 +1,7 @@ // Type definitions for find-versions 3.0 // Project: https://github.com/sindresorhus/find-versions // Definitions by: Leonid Logvinov -// Chris Arnesen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare function findVersions(version: string, options?: { loose: boolean }): string[]; From e8b63b0bdafe5b3f86c1f2eb062e77aef9fe99c6 Mon Sep 17 00:00:00 2001 From: Mathieu Ghennassia Date: Wed, 28 Nov 2018 11:52:15 +0100 Subject: [PATCH 157/792] mongodb: Type parameter update of method findOneAndUpdate --- types/mongodb/index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index ab4d2f4c02..f994ade210 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -79,7 +79,7 @@ export interface ClientSession extends EventEmitter { /** The server id associated with this session */ id: any; /** - * Aborts the currently active transaction in this session. + * Aborts the currently active transaction in this session. * @param {MongoCallback} [cb] Optional callback for completion of this operation */ abortTransaction(cb?: MongoCallback): Promise; @@ -89,7 +89,7 @@ export interface ClientSession extends EventEmitter { */ advanceOperationTime(operamtionTime: Timestamp): void; /** - * Commits the currently active transaction in this session. + * Commits the currently active transaction in this session. * @param {MongoCallback} [cb] Optional callback for completion of this operation */ commitTransaction(cb?: MongoCallback): Promise; @@ -110,7 +110,7 @@ export interface ClientSession extends EventEmitter { * Used to determine if this session equals another * * @param {ClientSession} session A class representing a client session on the server - * @returns {boolean} if the sessions are equal + * @returns {boolean} if the sessions are equal */ equals(session: ClientSession): boolean; @@ -118,13 +118,13 @@ export interface ClientSession extends EventEmitter { incrementTransactionNumber(): void; /** - * @returns {boolean} this session is currently in a transaction or not + * @returns {boolean} this session is currently in a transaction or not */ inTransaction(): boolean; /** * Starts a new transaction with the given options. - * @param {TransactionOptions} options + * @param {TransactionOptions} options * @memberof ClientSession */ startTransaction(options?: TransactionOptions): void; @@ -219,10 +219,10 @@ export class MongoError extends Error { * client/user (eg. "Email address must be unique" instead of "Both email * address and username must be unique") - which caters for a better (app) * user experience. - * + * * Details: https://github.com/Automattic/mongoose/issues/2129 (issue for * mongoose, but the same applies for the native mongodb driver) - * + * * Note that in mongoose (the link above) the prop in question is called * 'message' while in mongodb it is called 'errmsg'. This can be seen in * multiple places in the source code, for example here: @@ -706,9 +706,9 @@ export interface Collection { findOneAndReplace(filter: FilterQuery, replacement: Object, options?: FindOneAndReplaceOption): Promise>; findOneAndReplace(filter: FilterQuery, replacement: Object, options: FindOneAndReplaceOption, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate */ - findOneAndUpdate(filter: FilterQuery, update: Object, callback: MongoCallback>): void; - findOneAndUpdate(filter: FilterQuery, update: Object, options?: FindOneAndUpdateOption): Promise>; - findOneAndUpdate(filter: FilterQuery, update: Object, options: FindOneAndUpdateOption, callback: MongoCallback>): void; + findOneAndUpdate(filter: FilterQuery, update: UpdateQuery | TSchema, callback: MongoCallback>): void; + findOneAndUpdate(filter: FilterQuery, update: UpdateQuery | TSchema, options?: FindOneAndUpdateOption): Promise>; + findOneAndUpdate(filter: FilterQuery, update: UpdateQuery | TSchema, options: FindOneAndUpdateOption, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#geoHaystackSearch */ geoHaystackSearch(x: number, y: number, callback: MongoCallback): void; geoHaystackSearch(x: number, y: number, options?: GeoHaystackSearchOptions): Promise; From 1bec72c66668b0fd21dc7b23d7a9deae265ffa59 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 28 Nov 2018 12:56:06 +0100 Subject: [PATCH 158/792] [rosie] Fix sequence definition with builder argument --- types/rosie/index.d.ts | 2 +- types/rosie/rosie-tests.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/types/rosie/index.d.ts b/types/rosie/index.d.ts index 1078b53573..e66e9855eb 100644 --- a/types/rosie/index.d.ts +++ b/types/rosie/index.d.ts @@ -163,7 +163,7 @@ declare namespace rosie { * @param {function(number): *=} builder * @return {Factory} */ - sequence(name: keyof T, dependenciesOrBuilder?: () => any | keyof T[], builder?: Function) : IFactory; + sequence(name: keyof T, dependenciesOrBuilder?: (i: number) => any | keyof T[], builder?: Function) : IFactory; /** * Sets a post-processor callback that will receive built objects and the diff --git a/types/rosie/rosie-tests.ts b/types/rosie/rosie-tests.ts index 6c2152a9e7..86dd049732 100644 --- a/types/rosie/rosie-tests.ts +++ b/types/rosie/rosie-tests.ts @@ -19,6 +19,7 @@ resultObj = Factory.build('some'); Factory.define('coach') .option('buildPlayer', false) .sequence('id') + .sequence('name', (i: number) => `Coach${i}`) .attr('players', ['id', 'buildPlayer'], function(id: any, buildPlayer: boolean) { if (buildPlayer) { return [Factory.build('player', {coach_id: id})]; From d0081bef8b40ab5d104694063131acc928e5f78b Mon Sep 17 00:00:00 2001 From: HarikiRito <35214929+HarikiRito@users.noreply.github.com> Date: Wed, 28 Nov 2018 19:41:26 +0700 Subject: [PATCH 159/792] Export Interface --- types/react-lottie/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react-lottie/index.d.ts b/types/react-lottie/index.d.ts index 8e4f3b717b..a57da91307 100644 --- a/types/react-lottie/index.d.ts +++ b/types/react-lottie/index.d.ts @@ -7,7 +7,7 @@ import * as React from 'react'; -interface Options { +export interface Options { /** * Defines if the animation should play only once or repeatedly in an endless loop */ @@ -41,7 +41,7 @@ interface Options { }; } -interface EventListener { +export interface EventListener { /** * The event sent by Lottie */ @@ -61,7 +61,7 @@ interface EventListener { callback: () => void; } -interface LottieProps { +export interface LottieProps { /** * Object representing animation settings */ From 422ae215527764ce90c03fe262b401bdae07c17d Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 15:06:11 +0100 Subject: [PATCH 160/792] Update index.d.ts --- types/wikidata-sdk/index.d.ts | 243 ++++++++++++++++++++++++++-------- 1 file changed, 185 insertions(+), 58 deletions(-) diff --git a/types/wikidata-sdk/index.d.ts b/types/wikidata-sdk/index.d.ts index 5810bcc9de..79620ac623 100644 --- a/types/wikidata-sdk/index.d.ts +++ b/types/wikidata-sdk/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for wikidata-sdk 5.15 +// Type definitions for wikidata-sdk 5.15.9 // Project: https://github.com/maxlath/wikidata-sdk // Definitions by: Kamontat Chantrachirathumrong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -7,20 +7,36 @@ import { WikidataLanguage } from "./def/type/language"; import { WikidataProperty } from "./def/type/property"; import { WikidataSite } from "./def/type/site"; +import { WikidataSiteLink, WikidataSiteLinkSimplify, WikidataSiteLinkWithUrlSimplify } from "./def/object/sitelink"; import { UrlResultFormat } from "./def/type/format"; +import { + WikidataLanguageBaseString, + WikidataLanguageBaseStringSimplify, + WikidataLanguageBaseArrayString, + WikidataLanguageBaseArrayStringSimplify +} from "wikidata-sdk/def/object/language-base-string"; -import { Claim, MainSnak, TimeDataValue, EntityDataValue } from "./def/object/claim"; +import { WikidataClaim, WikidataMainSnak, WikidataTimeDataValue, WikidataEntityDataValue } from "./def/object/claim"; -export type WikidataLanguage = WikidataLanguage; -export type WikidataProperty = WikidataProperty; -export type WikidataSite = WikidataSite; +// ----------------------------------- // +// Export session // +// ----------------------------------- // -export type UrlResultFormat = UrlResultFormat; +export { WikidataLanguage, WikidataProperty, WikidataSite }; -export type Claim = Claim; -export type MainSnak = MainSnak; -export type TimeDataValue = TimeDataValue; -export type EntityDataValue = EntityDataValue; +export { + WikidataLanguageBaseString, + WikidataLanguageBaseStringSimplify, + WikidataLanguageBaseArrayString, + WikidataLanguageBaseArrayStringSimplify, + WikidataSiteLink, + WikidataSiteLinkSimplify, + WikidataSiteLinkWithUrlSimplify +}; + +export { UrlResultFormat }; + +export { WikidataClaim, WikidataMainSnak, WikidataTimeDataValue, WikidataEntityDataValue }; export as namespace sdk; @@ -42,22 +58,22 @@ export as namespace sdk; * @see {@link https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentities | Wikidata[wbsearchentities] } */ export function searchEntities( - search: string, - language?: WikidataLanguage, - limit?: string | number, - format?: UrlResultFormat, - uselang?: WikidataLanguage + search: string, + language?: WikidataLanguage, + limit?: string | number, + format?: UrlResultFormat, + uselang?: WikidataLanguage ): string; /** * @alias searchEntities */ export function searchEntities(opt: { - search: string; - language?: WikidataLanguage; - limit?: string | number; - format?: UrlResultFormat; - uselang?: WikidataLanguage; + search: string; + language?: WikidataLanguage; + limit?: string | number; + format?: UrlResultFormat; + uselang?: WikidataLanguage; }): string; /* ********** @@ -79,20 +95,20 @@ export function searchEntities(opt: { * @see {@link https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities | Wikidata[wbgetentities] } */ export function getEntities( - ids: string | string[], - languages?: WikidataLanguage | WikidataLanguage[], - props?: WikidataProperty | WikidataProperty[], - format?: UrlResultFormat + ids: string | string[], + languages?: WikidataLanguage | WikidataLanguage[], + props?: WikidataProperty | WikidataProperty[], + format?: UrlResultFormat ): string; /** * @alias getEntities */ export function getEntities(a: { - ids: string | string[]; - languages?: WikidataLanguage | WikidataLanguage[]; - props?: WikidataProperty | WikidataProperty[]; - format?: UrlResultFormat; + ids: string | string[]; + languages?: WikidataLanguage | WikidataLanguage[]; + props?: WikidataProperty | WikidataProperty[]; + format?: UrlResultFormat; }): string; /** @@ -101,20 +117,20 @@ export function getEntities(a: { * Without id limitation and return the array of url instead. */ export function getManyEntities( - ids: string | string[], - languages?: WikidataLanguage | WikidataLanguage[], - props?: WikidataProperty | WikidataProperty[], - format?: UrlResultFormat + ids: string | string[], + languages?: WikidataLanguage | WikidataLanguage[], + props?: WikidataProperty | WikidataProperty[], + format?: UrlResultFormat ): string[]; /** * @alias getManyEntities */ export function getManyEntities(a: { - ids: string | string[]; - languages?: WikidataLanguage | WikidataLanguage[]; - props?: WikidataProperty | WikidataProperty[]; - format?: UrlResultFormat; + ids: string | string[]; + languages?: WikidataLanguage | WikidataLanguage[]; + props?: WikidataProperty | WikidataProperty[]; + format?: UrlResultFormat; }): string[]; /** @@ -131,22 +147,22 @@ export function getManyEntities(a: { * @see {@link https://github.com/maxlath/wikidata-sdk/blob/6b0673b9bf0fcaab19db65e2cc77e33c901ef35d/docs/get_entities.md#by-wikipedia-titles | Github[get_entities.md#by-wikipedia-titles] } */ export function getWikidataIdsFromWikipediaTitles( - titles: string | string[], - sites?: string, - languages?: WikidataLanguage | WikidataLanguage[], - props?: WikidataProperty | WikidataProperty[], - format?: UrlResultFormat + titles: string | string[], + sites?: WikidataSite, + languages?: WikidataLanguage | WikidataLanguage[], + props?: WikidataProperty | WikidataProperty[], + format?: UrlResultFormat ): string; /** * @alias getWikidataIdsFromWikipediaTitles */ export function getWikidataIdsFromWikipediaTitles(a: { - titles: string | string[]; - sites?: string; - languages?: WikidataLanguage | WikidataLanguage[]; - props?: WikidataProperty | WikidataProperty[]; - format?: UrlResultFormat; + titles: string | string[]; + sites?: WikidataSite; + languages?: WikidataLanguage | WikidataLanguage[]; + props?: WikidataProperty | WikidataProperty[]; + format?: UrlResultFormat; }): string; /** @@ -167,13 +183,13 @@ export function getWikidataIdsFromWikipediaTitles(a: { * {@link https://github.com/maxlath/wikidata-sdk/blob/6b0673b9bf0fcaab19db65e2cc77e33c901ef35d/docs/get_entities_reverse_claims.md#get-entities-reverse-claims | Github[get-entities-reverse-claims] } */ export function getReverseClaims( - property: string | string[], - value: string | string[], - options?: { - limit?: number; - keepProperties?: boolean; - caseInsensitive?: boolean; - } + property: string | string[], + value: string | string[], + options?: { + limit?: number; + keepProperties?: boolean; + caseInsensitive?: boolean; + } ): string; /** @@ -241,7 +257,7 @@ export function truthyClaims(claims: object): object; * * @see {@link https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#Truthy_statements | Truthy} */ -export function truthyPropertyClaims(claims: Claim[]): Claim[]; +export function truthyPropertyClaims(claims: WikidataClaim[]): WikidataClaim[]; /** * This will get the link that represent the site of the title. @@ -252,16 +268,16 @@ export function truthyPropertyClaims(claims: Claim[]): Claim[]; * * @see {@link https://github.com/maxlath/wikidata-sdk/blob/6b0673b9bf0fcaab19db65e2cc77e33c901ef35d/docs/general_helpers.md#getsitelinkurl | Github[getsitelinkurl] } */ -export function getSitelinkUrl(site: string, title: string): string; +export function getSitelinkUrl(site: WikidataSite, title: string): string; /** * @alias getSitelinkUrl */ -export function getSitelinkUrl(a: { site: string; title: string }): string; +export function getSitelinkUrl(a: { site: WikidataSite; title: string }): string; export interface SitelinkData { - lang: string; - project: string; + lang: string; + project: string; } /** * Get the sitelink on english language and the lang of it. @@ -335,3 +351,114 @@ export function wikidataTimeToSimpleDay(a: string | object): string; * @returns URL from a wikimedia commons filename */ export function getImageUrl(a: string, width?: number): string; + +export type SimplifyOption = { + // claims + entityPrefix?: string; + propertyPrefix?: string; + keepRichValues?: boolean; + keepQualifiers?: boolean; + keepReferences?: boolean; + keepIds?: boolean; + keepHashes?: boolean; + keepNonTruthy?: boolean; + // sitelinks + addUrl?: boolean; +}; + +/** + * Helper method, for simplify result object more reasonable + */ +export namespace simplify { + /** + * Applying all simplifiers at once: labels, descriptions, aliases, claims, sitelinks. See next sections for details. + * You can also pass options as a second argument, that will then be passed the subfunctions: + * + * @param entity the entity that receive from {@link getEntities} APIs + * @param opt simlify option. currently only simplify claims and simplify sitelinks. + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-entity | Github[simplify-entity]} + */ + export function entity(entity: T, opt?: SimplifyOption): T; + + /** + * This is a same of {@link entity} method except this input as multiple array of entities. + * + * @param entities entities from {@link getEntities} APIs + * @param opt simlify option. currently only simplify claims and simplify sitelinks. + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-entities | Github[simplify-entities]} + */ + export function entities(entities: T[], opt?: SimplifyOption): T[]; + + /** + * Make label simplifier and easier to understand + * + * @param labels label object, you will receive this from getEntities method + * + * @example + * + * const label = simplify.labels("{ pl: { language: 'pl', value: 'ksiΔ…ΕΌka' } }"); + * console.log(label) // { pl: 'ksiΔ…ΕΌka' } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-labels | Github[simplify-labels]} + */ + export function labels(labels: WikidataLanguageBaseString): WikidataLanguageBaseStringSimplify; + + /** + * Make description simplifier and easier to understand + * + * @param descriptions description object, you will receive this from getEntities method + * + * @example + * + * const desc = simplify.descriptions("{ pl: { language: 'pl', value: 'dokument piΕ›mienniczy [...]' } }"); + * console.log(desc) // { pl: 'dokument piΕ›mienniczy [...]' } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-descriptions | Github[simplify-descriptions]} + */ + export function descriptions(descriptions: WikidataLanguageBaseString): WikidataLanguageBaseStringSimplify; + + /** + * Make alias simplifier and easier to understand + * + * @param aliases alias object, you will receive this from getEntities method + * + * @example + * + * const alias = simplify.aliases("{ pl: [ { language: 'pl', value: 'Tom' }, { language: 'pl', value: 'Tomik' } ] }"); + * console.log(alias) // { pl: [ 'Tom', 'Tomik' ] } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-aliases | Github[simplify-aliases]} + */ + export function aliases(aliases: WikidataLanguageBaseArrayString): WikidataLanguageBaseArrayStringSimplify; + + /** + * Make sitelink simplifier and easier to understand + * + * @param sitelinks sitelink object, you will receive this from getEntities method + * + * @example + * + * const site = simplify.sitelinks("{ plwiki: { site: 'plwiki', title: 'KsiΔ…ΕΌka', badges: [] } }"); + * console.log(site) // { plwiki: 'KsiΔ…ΕΌka' } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-sitelinks | Github[simplify-sitelinks]} + */ + export function sitelinks(sitelinks: WikidataSiteLink): WikidataSiteLinkSimplify; + + /** + * Make sitelink simplifier and easier to understand. include URL in the result. + * + * @param sitelinks sitelink object, you will receive this from getEntities method + * @param options add url to a result + * + * @example + * + * const site = simplify.sitelinks("{ plwiki: { site: 'plwiki', title: 'KsiΔ…ΕΌka', badges: [] } }", {addUrl: true}); + * console.log(site) // { plwiki: { title: 'KsiΔ…ΕΌka', url: 'https://pl.wikipedia.org/wiki/KsiΔ…ΕΌka' } } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#add-sitelinks-urls | Github[simplify-sitelinks-with-url]} + */ + export function sitelinks(sitelinks: WikidataSiteLink, options: { addUrl: true }): WikidataSiteLinkWithUrlSimplify; +} From d284105dcadcce897d96a1d38a5040e396095f35 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 15:08:33 +0100 Subject: [PATCH 161/792] Update claim name --- types/wikidata-sdk/def/object/claim.d.ts | 54 ++++++++++++------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/types/wikidata-sdk/def/object/claim.d.ts b/types/wikidata-sdk/def/object/claim.d.ts index c397fcb0df..99ed8bf52c 100644 --- a/types/wikidata-sdk/def/object/claim.d.ts +++ b/types/wikidata-sdk/def/object/claim.d.ts @@ -1,34 +1,34 @@ -export interface TimeDataValue { - type: "time"; - value: { - time: string; - timezone: number; - before: number; - after: number; - precision: number; - calendermodel: string; - }; +export interface WikidataTimeDataValue { + type: "time"; + value: { + time: string; + timezone: number; + before: number; + after: number; + precision: number; + calendermodel: string; + }; } -export interface EntityDataValue { - type: "wikibase-entityid"; - value: { - "numeric-id": number; - "entity-type": string; - }; +export interface WikidataEntityDataValue { + type: "wikibase-entityid"; + value: { + "numeric-id": number; + "entity-type": string; + }; } -export interface MainSnak { - datatype: string; - snaktype: string; - property: string; - hash: string; - datavalue: TimeDataValue | EntityDataValue; +export interface WikidataMainSnak { + datatype: string; + snaktype: string; + property: string; + hash: string; + datavalue: WikidataTimeDataValue | WikidataEntityDataValue; } -export interface Claim { - rank: string; - id: string; - type: string; - mainsnak: MainSnak; +export interface WikidataClaim { + rank: string; + id: string; + type: string; + mainsnak: WikidataMainSnak; } From d5acd49750e454a5ab7f35a452a2f2cd61ea12ea Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 15:09:17 +0100 Subject: [PATCH 162/792] Add language base string object type --- .../def/object/language-base-string.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 types/wikidata-sdk/def/object/language-base-string.d.ts diff --git a/types/wikidata-sdk/def/object/language-base-string.d.ts b/types/wikidata-sdk/def/object/language-base-string.d.ts new file mode 100644 index 0000000000..9f35d4bd8e --- /dev/null +++ b/types/wikidata-sdk/def/object/language-base-string.d.ts @@ -0,0 +1,19 @@ +import { WikidataLanguage } from "wikidata-sdk"; + +export type WikidataLanguageBaseString = { + [Key in WikidataLanguage]?: { + language: Key; + value: string; + } +}; + +export type WikidataLanguageBaseStringSimplify = { [key in WikidataLanguage]?: string }; + +export type WikidataLanguageBaseArrayString = { + [Key in WikidataLanguage]: { + language: Key; + value: string; + }[] +}; + +export type WikidataLanguageBaseArrayStringSimplify = { [key in WikidataLanguage]: string[] }; From 22e936663027c8f82280ce4a3883fe42ea30e8ee Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 15:09:40 +0100 Subject: [PATCH 163/792] Add sitelink object --- types/wikidata-sdk/def/object/sitelink.d.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 types/wikidata-sdk/def/object/sitelink.d.ts diff --git a/types/wikidata-sdk/def/object/sitelink.d.ts b/types/wikidata-sdk/def/object/sitelink.d.ts new file mode 100644 index 0000000000..4b6aeee23d --- /dev/null +++ b/types/wikidata-sdk/def/object/sitelink.d.ts @@ -0,0 +1,12 @@ +import { WikidataSite } from "wikidata-sdk"; + +export type WikidataSiteLink = { [Key in WikidataSite]: { site: Key; title: string; badges: string[] } }; + +export type WikidataSiteLinkSimplify = { [key in WikidataSite]: string }; + +export type WikidataSiteLinkWithUrlSimplify = { + [key in WikidataSite]: { + title: string; + url: string; + } +}; From 3e65f7972871d987b69b60a2b63587a89e5dbb6f Mon Sep 17 00:00:00 2001 From: feinoujc Date: Wed, 28 Nov 2018 09:10:50 -0500 Subject: [PATCH 164/792] [@pollyjs/core] updates for 1.3 config options --- types/pollyjs__core/index.d.ts | 28 +++++---- types/pollyjs__core/pollyjs__core-tests.ts | 69 +++++++++++++++++++++- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/types/pollyjs__core/index.d.ts b/types/pollyjs__core/index.d.ts index 83b6b933b9..4f6d308d0d 100644 --- a/types/pollyjs__core/index.d.ts +++ b/types/pollyjs__core/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for @pollyjs/core 1.2 +// Type definitions for @pollyjs/core 1.3 // Project: https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/core // Definitions by: feinoujc // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -12,8 +12,10 @@ export const Timing: { fixed(ms: number): () => Promise; relative(ratio: number): (ms: number) => Promise; }; + +export type MatchBy = (input: T) => R; export interface PollyConfig { - mode?: MODES; + mode?: MODES | string; adapters?: Array; adapterOptions?: any; @@ -34,20 +36,20 @@ export interface PollyConfig { timing?: ((ms: number) => Promise) | (() => Promise); matchRequestsBy?: { - method?: boolean; - headers?: any; - body?: boolean; + method?: boolean | MatchBy; + headers?: boolean | { exclude: string[] } | MatchBy>; + body?: boolean | MatchBy; order?: boolean; url?: { - protocol?: boolean; - username?: boolean; - password?: boolean; - hostname?: boolean; - port?: boolean; - pathname?: boolean; - query?: boolean; - hash?: boolean; + protocol?: boolean | MatchBy; + username?: boolean | MatchBy; + password?: boolean | MatchBy; + hostname?: boolean | MatchBy; + port?: boolean | MatchBy; + pathname?: boolean | MatchBy; + query?: boolean | MatchBy; + hash?: boolean | MatchBy; }; }; } diff --git a/types/pollyjs__core/pollyjs__core-tests.ts b/types/pollyjs__core/pollyjs__core-tests.ts index 22f5516646..0644eff7f4 100644 --- a/types/pollyjs__core/pollyjs__core-tests.ts +++ b/types/pollyjs__core/pollyjs__core-tests.ts @@ -6,7 +6,74 @@ const polly = new Polly('test recording', { recordFailedRequests: true, adapters: ['xhr', 'fetch'], persister: 'rest', - timing: Timing.relative(3) + timing: Timing.relative(3), + matchRequestsBy: { + method: true, + headers: true, + body: true, + order: true, + + url: { + protocol: true, + username: true, + password: true, + hostname: true, + port: true, + pathname: true, + query: true, + hash: false + } + } +}); + +new Polly('test recording', { + mode: 'replay', + recordFailedRequests: true, + adapters: ['xhr', 'fetch'], + persister: 'rest', + timing: Timing.relative(3), + matchRequestsBy: { + method(method) { + return method.toLowerCase(); + }, + headers: 1 === 1 ? { exclude: ['X-Auth'] } : (headers) => { + delete headers['X-Auth']; + return headers; + }, + body(body) { + const json = JSON.parse(body); + + delete json.email; + return JSON.stringify(json); + }, + + url: { + protocol(protocol) { + return protocol === 'http' ? 'https:' : protocol; + }, + username(username) { + return username === 'johndoe' ? 'username' : username; + }, + password(password) { + return password || 'password'; + }, + hostname(hostname) { + return hostname.replace('.com', '.net'); + }, + port(port) { + return port > 80 ? 3000 : 433; + }, + pathname(pathname) { + return pathname.replace('/api/v1', '/api'); + }, + query(query) { + return { ...query, token: '' }; + }, + hash(hash) { + return hash.replace(/token=[0-9]+/, ''); + } + } + } }); function log(_: string) { From 091bd02a320f8984ff9b7045efab32737d631b93 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 15:14:48 +0100 Subject: [PATCH 165/792] Fix error --- types/wikidata-sdk/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/wikidata-sdk/index.d.ts b/types/wikidata-sdk/index.d.ts index 79620ac623..98eb893d0c 100644 --- a/types/wikidata-sdk/index.d.ts +++ b/types/wikidata-sdk/index.d.ts @@ -14,7 +14,7 @@ import { WikidataLanguageBaseStringSimplify, WikidataLanguageBaseArrayString, WikidataLanguageBaseArrayStringSimplify -} from "wikidata-sdk/def/object/language-base-string"; +} from "./def/object/language-base-string"; import { WikidataClaim, WikidataMainSnak, WikidataTimeDataValue, WikidataEntityDataValue } from "./def/object/claim"; From 19d012663d76ff38c8ade084095cfef40556fad2 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Wed, 28 Nov 2018 17:25:18 +0300 Subject: [PATCH 166/792] add on-initial-draw-complete-support --- types/vis/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/vis/index.d.ts b/types/vis/index.d.ts index 0f4a4f0f4e..9967c35061 100644 --- a/types/vis/index.d.ts +++ b/types/vis/index.d.ts @@ -11,6 +11,7 @@ // Oleksii Kachura // dcop // Avraham Essoudry +// Dmitriy Trifonov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import { MomentInput, MomentFormatSpecification, Moment } from 'moment'; @@ -244,6 +245,7 @@ export interface TimelineOptions { multiselectPerGroup?: boolean; onAdd?: TimelineOptionsItemCallbackFunction; onAddGroup?: TimelineOptionsGroupCallbackFunction; + onInitialDrawComplete?: () => void; onUpdate?: TimelineOptionsItemCallbackFunction; onMove?: TimelineOptionsItemCallbackFunction; onMoveGroup?: TimelineOptionsGroupCallbackFunction; From 265766df3dfefc749ecd229354e8ca884c8cf818 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 15:32:28 +0100 Subject: [PATCH 167/792] [fix] Fix a lot of linter error --- .../def/object/language-base-string.d.ts | 18 +- types/wikidata-sdk/def/object/sitelink.d.ts | 10 +- types/wikidata-sdk/index.d.ts | 320 +++++++++--------- 3 files changed, 176 insertions(+), 172 deletions(-) diff --git a/types/wikidata-sdk/def/object/language-base-string.d.ts b/types/wikidata-sdk/def/object/language-base-string.d.ts index 9f35d4bd8e..8f9606dbb1 100644 --- a/types/wikidata-sdk/def/object/language-base-string.d.ts +++ b/types/wikidata-sdk/def/object/language-base-string.d.ts @@ -1,19 +1,19 @@ -import { WikidataLanguage } from "wikidata-sdk"; +import { WikidataLanguage } from "../type/language"; export type WikidataLanguageBaseString = { - [Key in WikidataLanguage]?: { - language: Key; - value: string; - } + [Key in WikidataLanguage]?: { + language: Key; + value: string; + } }; export type WikidataLanguageBaseStringSimplify = { [key in WikidataLanguage]?: string }; export type WikidataLanguageBaseArrayString = { - [Key in WikidataLanguage]: { - language: Key; - value: string; - }[] + [Key in WikidataLanguage]: Array<{ + language: Key; + value: string; + }> }; export type WikidataLanguageBaseArrayStringSimplify = { [key in WikidataLanguage]: string[] }; diff --git a/types/wikidata-sdk/def/object/sitelink.d.ts b/types/wikidata-sdk/def/object/sitelink.d.ts index 4b6aeee23d..d0eea713e5 100644 --- a/types/wikidata-sdk/def/object/sitelink.d.ts +++ b/types/wikidata-sdk/def/object/sitelink.d.ts @@ -1,12 +1,12 @@ -import { WikidataSite } from "wikidata-sdk"; +import { WikidataSite } from "../type/site"; export type WikidataSiteLink = { [Key in WikidataSite]: { site: Key; title: string; badges: string[] } }; export type WikidataSiteLinkSimplify = { [key in WikidataSite]: string }; export type WikidataSiteLinkWithUrlSimplify = { - [key in WikidataSite]: { - title: string; - url: string; - } + [key in WikidataSite]: { + title: string; + url: string; + } }; diff --git a/types/wikidata-sdk/index.d.ts b/types/wikidata-sdk/index.d.ts index 98eb893d0c..6ed81883cc 100644 --- a/types/wikidata-sdk/index.d.ts +++ b/types/wikidata-sdk/index.d.ts @@ -1,8 +1,8 @@ -// Type definitions for wikidata-sdk 5.15.9 +// Type definitions for wikidata-sdk 5.15 // Project: https://github.com/maxlath/wikidata-sdk // Definitions by: Kamontat Chantrachirathumrong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 +// TypeScript Version: 2.1 import { WikidataLanguage } from "./def/type/language"; import { WikidataProperty } from "./def/type/property"; @@ -10,10 +10,10 @@ import { WikidataSite } from "./def/type/site"; import { WikidataSiteLink, WikidataSiteLinkSimplify, WikidataSiteLinkWithUrlSimplify } from "./def/object/sitelink"; import { UrlResultFormat } from "./def/type/format"; import { - WikidataLanguageBaseString, - WikidataLanguageBaseStringSimplify, - WikidataLanguageBaseArrayString, - WikidataLanguageBaseArrayStringSimplify + WikidataLanguageBaseString, + WikidataLanguageBaseStringSimplify, + WikidataLanguageBaseArrayString, + WikidataLanguageBaseArrayStringSimplify } from "./def/object/language-base-string"; import { WikidataClaim, WikidataMainSnak, WikidataTimeDataValue, WikidataEntityDataValue } from "./def/object/claim"; @@ -25,19 +25,23 @@ import { WikidataClaim, WikidataMainSnak, WikidataTimeDataValue, WikidataEntityD export { WikidataLanguage, WikidataProperty, WikidataSite }; export { - WikidataLanguageBaseString, - WikidataLanguageBaseStringSimplify, - WikidataLanguageBaseArrayString, - WikidataLanguageBaseArrayStringSimplify, - WikidataSiteLink, - WikidataSiteLinkSimplify, - WikidataSiteLinkWithUrlSimplify + WikidataLanguageBaseString, + WikidataLanguageBaseStringSimplify, + WikidataLanguageBaseArrayString, + WikidataLanguageBaseArrayStringSimplify, + WikidataSiteLink, + WikidataSiteLinkSimplify, + WikidataSiteLinkWithUrlSimplify }; export { UrlResultFormat }; export { WikidataClaim, WikidataMainSnak, WikidataTimeDataValue, WikidataEntityDataValue }; +export interface Json { + [key: string]: any; +} + export as namespace sdk; /* ********** @@ -58,22 +62,22 @@ export as namespace sdk; * @see {@link https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentities | Wikidata[wbsearchentities] } */ export function searchEntities( - search: string, - language?: WikidataLanguage, - limit?: string | number, - format?: UrlResultFormat, - uselang?: WikidataLanguage + search: string, + language?: WikidataLanguage, + limit?: string | number, + format?: UrlResultFormat, + uselang?: WikidataLanguage ): string; /** * @alias searchEntities */ export function searchEntities(opt: { - search: string; - language?: WikidataLanguage; - limit?: string | number; - format?: UrlResultFormat; - uselang?: WikidataLanguage; + search: string; + language?: WikidataLanguage; + limit?: string | number; + format?: UrlResultFormat; + uselang?: WikidataLanguage; }): string; /* ********** @@ -95,20 +99,20 @@ export function searchEntities(opt: { * @see {@link https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities | Wikidata[wbgetentities] } */ export function getEntities( - ids: string | string[], - languages?: WikidataLanguage | WikidataLanguage[], - props?: WikidataProperty | WikidataProperty[], - format?: UrlResultFormat + ids: string | string[], + languages?: WikidataLanguage | WikidataLanguage[], + props?: WikidataProperty | WikidataProperty[], + format?: UrlResultFormat ): string; /** * @alias getEntities */ export function getEntities(a: { - ids: string | string[]; - languages?: WikidataLanguage | WikidataLanguage[]; - props?: WikidataProperty | WikidataProperty[]; - format?: UrlResultFormat; + ids: string | string[]; + languages?: WikidataLanguage | WikidataLanguage[]; + props?: WikidataProperty | WikidataProperty[]; + format?: UrlResultFormat; }): string; /** @@ -117,20 +121,20 @@ export function getEntities(a: { * Without id limitation and return the array of url instead. */ export function getManyEntities( - ids: string | string[], - languages?: WikidataLanguage | WikidataLanguage[], - props?: WikidataProperty | WikidataProperty[], - format?: UrlResultFormat + ids: string | string[], + languages?: WikidataLanguage | WikidataLanguage[], + props?: WikidataProperty | WikidataProperty[], + format?: UrlResultFormat ): string[]; /** * @alias getManyEntities */ export function getManyEntities(a: { - ids: string | string[]; - languages?: WikidataLanguage | WikidataLanguage[]; - props?: WikidataProperty | WikidataProperty[]; - format?: UrlResultFormat; + ids: string | string[]; + languages?: WikidataLanguage | WikidataLanguage[]; + props?: WikidataProperty | WikidataProperty[]; + format?: UrlResultFormat; }): string[]; /** @@ -147,22 +151,22 @@ export function getManyEntities(a: { * @see {@link https://github.com/maxlath/wikidata-sdk/blob/6b0673b9bf0fcaab19db65e2cc77e33c901ef35d/docs/get_entities.md#by-wikipedia-titles | Github[get_entities.md#by-wikipedia-titles] } */ export function getWikidataIdsFromWikipediaTitles( - titles: string | string[], - sites?: WikidataSite, - languages?: WikidataLanguage | WikidataLanguage[], - props?: WikidataProperty | WikidataProperty[], - format?: UrlResultFormat + titles: string | string[], + sites?: WikidataSite, + languages?: WikidataLanguage | WikidataLanguage[], + props?: WikidataProperty | WikidataProperty[], + format?: UrlResultFormat ): string; /** * @alias getWikidataIdsFromWikipediaTitles */ export function getWikidataIdsFromWikipediaTitles(a: { - titles: string | string[]; - sites?: WikidataSite; - languages?: WikidataLanguage | WikidataLanguage[]; - props?: WikidataProperty | WikidataProperty[]; - format?: UrlResultFormat; + titles: string | string[]; + sites?: WikidataSite; + languages?: WikidataLanguage | WikidataLanguage[]; + props?: WikidataProperty | WikidataProperty[]; + format?: UrlResultFormat; }): string; /** @@ -183,13 +187,13 @@ export function getWikidataIdsFromWikipediaTitles(a: { * {@link https://github.com/maxlath/wikidata-sdk/blob/6b0673b9bf0fcaab19db65e2cc77e33c901ef35d/docs/get_entities_reverse_claims.md#get-entities-reverse-claims | Github[get-entities-reverse-claims] } */ export function getReverseClaims( - property: string | string[], - value: string | string[], - options?: { - limit?: number; - keepProperties?: boolean; - caseInsensitive?: boolean; - } + property: string | string[], + value: string | string[], + options?: { + limit?: number; + keepProperties?: boolean; + caseInsensitive?: boolean; + } ): string; /** @@ -248,7 +252,7 @@ export function isSitelinkKey(a: string): boolean; * * @see {@link https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#Truthy_statements | Truthy} */ -export function truthyClaims(claims: object): object; +export function truthyClaims(claims: WikidataClaim): WikidataClaim; /** * Filter-out non-truthy claims from an entity.claims[prop] array @@ -276,8 +280,8 @@ export function getSitelinkUrl(site: WikidataSite, title: string): string; export function getSitelinkUrl(a: { site: WikidataSite; title: string }): string; export interface SitelinkData { - lang: string; - project: string; + lang: string; + project: string; } /** * Get the sitelink on english language and the lang of it. @@ -340,7 +344,7 @@ export function wikidataTimeToDateObject(a: string): Date; * @see {@link https://github.com/maxlath/wikidata-sdk/blob/6b0673b9bf0fcaab19db65e2cc77e33c901ef35d/docs/general_helpers.md#wikidatatimetosimpleday | Github[wikidatatimetosimpleday] } * */ -export function wikidataTimeToSimpleDay(a: string | object): string; +export function wikidataTimeToSimpleDay(a: string | Json): string; /** * Get an image URL from a Wikimedia Commons filename @@ -352,113 +356,113 @@ export function wikidataTimeToSimpleDay(a: string | object): string; */ export function getImageUrl(a: string, width?: number): string; -export type SimplifyOption = { - // claims - entityPrefix?: string; - propertyPrefix?: string; - keepRichValues?: boolean; - keepQualifiers?: boolean; - keepReferences?: boolean; - keepIds?: boolean; - keepHashes?: boolean; - keepNonTruthy?: boolean; - // sitelinks - addUrl?: boolean; -}; +export interface SimplifyOption { + // claims + entityPrefix?: string; + propertyPrefix?: string; + keepRichValues?: boolean; + keepQualifiers?: boolean; + keepReferences?: boolean; + keepIds?: boolean; + keepHashes?: boolean; + keepNonTruthy?: boolean; + // sitelinks + addUrl?: boolean; +} /** * Helper method, for simplify result object more reasonable */ export namespace simplify { - /** - * Applying all simplifiers at once: labels, descriptions, aliases, claims, sitelinks. See next sections for details. - * You can also pass options as a second argument, that will then be passed the subfunctions: - * - * @param entity the entity that receive from {@link getEntities} APIs - * @param opt simlify option. currently only simplify claims and simplify sitelinks. - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-entity | Github[simplify-entity]} - */ - export function entity(entity: T, opt?: SimplifyOption): T; + /** + * Applying all simplifiers at once: labels, descriptions, aliases, claims, sitelinks. See next sections for details. + * You can also pass options as a second argument, that will then be passed the subfunctions: + * + * @param entity the entity that receive from {@link getEntities} APIs + * @param opt simlify option. currently only simplify claims and simplify sitelinks. + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-entity | Github[simplify-entity]} + */ + function entity(entity: T, opt?: SimplifyOption): T; - /** - * This is a same of {@link entity} method except this input as multiple array of entities. - * - * @param entities entities from {@link getEntities} APIs - * @param opt simlify option. currently only simplify claims and simplify sitelinks. - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-entities | Github[simplify-entities]} - */ - export function entities(entities: T[], opt?: SimplifyOption): T[]; + /** + * This is a same of {@link entity} method except this input as multiple array of entities. + * + * @param entities entities from {@link getEntities} APIs + * @param opt simlify option. currently only simplify claims and simplify sitelinks. + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-entities | Github[simplify-entities]} + */ + function entities(entities: T[], opt?: SimplifyOption): T[]; - /** - * Make label simplifier and easier to understand - * - * @param labels label object, you will receive this from getEntities method - * - * @example - * - * const label = simplify.labels("{ pl: { language: 'pl', value: 'ksiΔ…ΕΌka' } }"); - * console.log(label) // { pl: 'ksiΔ…ΕΌka' } - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-labels | Github[simplify-labels]} - */ - export function labels(labels: WikidataLanguageBaseString): WikidataLanguageBaseStringSimplify; + /** + * Make label simplifier and easier to understand + * + * @param labels label object, you will receive this from getEntities method + * + * @example + * + * const label = simplify.labels("{ pl: { language: 'pl', value: 'ksiΔ…ΕΌka' } }"); + * console.log(label) // { pl: 'ksiΔ…ΕΌka' } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-labels | Github[simplify-labels]} + */ + function labels(labels: WikidataLanguageBaseString): WikidataLanguageBaseStringSimplify; - /** - * Make description simplifier and easier to understand - * - * @param descriptions description object, you will receive this from getEntities method - * - * @example - * - * const desc = simplify.descriptions("{ pl: { language: 'pl', value: 'dokument piΕ›mienniczy [...]' } }"); - * console.log(desc) // { pl: 'dokument piΕ›mienniczy [...]' } - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-descriptions | Github[simplify-descriptions]} - */ - export function descriptions(descriptions: WikidataLanguageBaseString): WikidataLanguageBaseStringSimplify; + /** + * Make description simplifier and easier to understand + * + * @param descriptions description object, you will receive this from getEntities method + * + * @example + * + * const desc = simplify.descriptions("{ pl: { language: 'pl', value: 'dokument piΕ›mienniczy [...]' } }"); + * console.log(desc) // { pl: 'dokument piΕ›mienniczy [...]' } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-descriptions | Github[simplify-descriptions]} + */ + function descriptions(descriptions: WikidataLanguageBaseString): WikidataLanguageBaseStringSimplify; - /** - * Make alias simplifier and easier to understand - * - * @param aliases alias object, you will receive this from getEntities method - * - * @example - * - * const alias = simplify.aliases("{ pl: [ { language: 'pl', value: 'Tom' }, { language: 'pl', value: 'Tomik' } ] }"); - * console.log(alias) // { pl: [ 'Tom', 'Tomik' ] } - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-aliases | Github[simplify-aliases]} - */ - export function aliases(aliases: WikidataLanguageBaseArrayString): WikidataLanguageBaseArrayStringSimplify; + /** + * Make alias simplifier and easier to understand + * + * @param aliases alias object, you will receive this from getEntities method + * + * @example + * + * const alias = simplify.aliases("{ pl: [ { language: 'pl', value: 'Tom' }, { language: 'pl', value: 'Tomik' } ] }"); + * console.log(alias) // { pl: [ 'Tom', 'Tomik' ] } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-aliases | Github[simplify-aliases]} + */ + function aliases(aliases: WikidataLanguageBaseArrayString): WikidataLanguageBaseArrayStringSimplify; - /** - * Make sitelink simplifier and easier to understand - * - * @param sitelinks sitelink object, you will receive this from getEntities method - * - * @example - * - * const site = simplify.sitelinks("{ plwiki: { site: 'plwiki', title: 'KsiΔ…ΕΌka', badges: [] } }"); - * console.log(site) // { plwiki: 'KsiΔ…ΕΌka' } - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-sitelinks | Github[simplify-sitelinks]} - */ - export function sitelinks(sitelinks: WikidataSiteLink): WikidataSiteLinkSimplify; + /** + * Make sitelink simplifier and easier to understand + * + * @param sitelinks sitelink object, you will receive this from getEntities method + * + * @example + * + * const site = simplify.sitelinks("{ plwiki: { site: 'plwiki', title: 'KsiΔ…ΕΌka', badges: [] } }"); + * console.log(site) // { plwiki: 'KsiΔ…ΕΌka' } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#simplify-sitelinks | Github[simplify-sitelinks]} + */ + function sitelinks(sitelinks: WikidataSiteLink): WikidataSiteLinkSimplify; - /** - * Make sitelink simplifier and easier to understand. include URL in the result. - * - * @param sitelinks sitelink object, you will receive this from getEntities method - * @param options add url to a result - * - * @example - * - * const site = simplify.sitelinks("{ plwiki: { site: 'plwiki', title: 'KsiΔ…ΕΌka', badges: [] } }", {addUrl: true}); - * console.log(site) // { plwiki: { title: 'KsiΔ…ΕΌka', url: 'https://pl.wikipedia.org/wiki/KsiΔ…ΕΌka' } } - * - * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#add-sitelinks-urls | Github[simplify-sitelinks-with-url]} - */ - export function sitelinks(sitelinks: WikidataSiteLink, options: { addUrl: true }): WikidataSiteLinkWithUrlSimplify; + /** + * Make sitelink simplifier and easier to understand. include URL in the result. + * + * @param sitelinks sitelink object, you will receive this from getEntities method + * @param options add url to a result + * + * @example + * + * const site = simplify.sitelinks("{ plwiki: { site: 'plwiki', title: 'KsiΔ…ΕΌka', badges: [] } }", {addUrl: true}); + * console.log(site) // { plwiki: { title: 'KsiΔ…ΕΌka', url: 'https://pl.wikipedia.org/wiki/KsiΔ…ΕΌka' } } + * + * @see {@link https://github.com/maxlath/wikidata-sdk/blob/master/docs/simplify_entities_data.md#add-sitelinks-urls | Github[simplify-sitelinks-with-url]} + */ + function sitelinks(sitelinks: WikidataSiteLink, options: { addUrl: true }): WikidataSiteLinkWithUrlSimplify; } From b53181d81ab75724f19b0f1fb242525639c1f96f Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Wed, 28 Nov 2018 17:36:58 +0300 Subject: [PATCH 168/792] change void function type --- types/vis/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/vis/index.d.ts b/types/vis/index.d.ts index 9967c35061..84ff769270 100644 --- a/types/vis/index.d.ts +++ b/types/vis/index.d.ts @@ -245,7 +245,7 @@ export interface TimelineOptions { multiselectPerGroup?: boolean; onAdd?: TimelineOptionsItemCallbackFunction; onAddGroup?: TimelineOptionsGroupCallbackFunction; - onInitialDrawComplete?: () => void; + onInitialDrawComplete?: (() => void); onUpdate?: TimelineOptionsItemCallbackFunction; onMove?: TimelineOptionsItemCallbackFunction; onMoveGroup?: TimelineOptionsGroupCallbackFunction; From 0f51eb8eeab7859c7eafbc3506f5ab65d3cfc267 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 28 Nov 2018 16:23:49 +0100 Subject: [PATCH 169/792] Add types for mustache-express --- types/mustache-express/index.d.ts | 23 +++++++++++++++++++ .../mustache-express-tests.ts | 10 ++++++++ types/mustache-express/tsconfig.json | 23 +++++++++++++++++++ types/mustache-express/tslint.json | 1 + 4 files changed, 57 insertions(+) create mode 100644 types/mustache-express/index.d.ts create mode 100644 types/mustache-express/mustache-express-tests.ts create mode 100644 types/mustache-express/tsconfig.json create mode 100644 types/mustache-express/tslint.json diff --git a/types/mustache-express/index.d.ts b/types/mustache-express/index.d.ts new file mode 100644 index 0000000000..ff40de42d7 --- /dev/null +++ b/types/mustache-express/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for mustache-express 1.2 +// Project: https://github.com/bryanburgers/node-mustache-express#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Cache } from 'lru-cache'; + +export = mustacheExpress; + +declare function mustacheExpress( + partialsPath?: string, + partialsExt?: string +): mustacheExpress.ExpessEngine; + +declare namespace mustacheExpress { + interface ExpessEngine { + (path: string, options: any, cb: (...args: any[]) => any): any; + cache: TemplateCache; + } + + type TemplateCache = Cache; +} diff --git a/types/mustache-express/mustache-express-tests.ts b/types/mustache-express/mustache-express-tests.ts new file mode 100644 index 0000000000..9157798c7b --- /dev/null +++ b/types/mustache-express/mustache-express-tests.ts @@ -0,0 +1,10 @@ +import express = require('express'); +import mustacheExpress = require('mustache-express'); + +const app = express(); +app.engine('mustache', mustacheExpress()); +app.engine('mustache', mustacheExpress('/partials')); +app.engine('mustache', mustacheExpress('/partials', '.mst')); + +// $ExpectType Cache +mustacheExpress().cache; diff --git a/types/mustache-express/tsconfig.json b/types/mustache-express/tsconfig.json new file mode 100644 index 0000000000..9afb989b62 --- /dev/null +++ b/types/mustache-express/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mustache-express-tests.ts" + ] +} diff --git a/types/mustache-express/tslint.json b/types/mustache-express/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mustache-express/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 793d709fb22bb195371fd52fa0a8d50a39e4accf Mon Sep 17 00:00:00 2001 From: Lucas Motta Date: Wed, 28 Nov 2018 16:16:54 +0000 Subject: [PATCH 170/792] Include missing type for the method readFile --- types/ssh2-streams/index.d.ts | 24 ++++++++++++++++++++++++ types/ssh2/index.d.ts | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/types/ssh2-streams/index.d.ts b/types/ssh2-streams/index.d.ts index a780273591..3eaca56f6f 100644 --- a/types/ssh2-streams/index.d.ts +++ b/types/ssh2-streams/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for ssh2-streams v0.1.9 // Project: https://github.com/mscdex/ssh2-streams // Definitions by: Ron Buckton +// Definitions by: Ron Buckton // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -1044,6 +1045,24 @@ export class SFTPStream extends stream.Transform { */ fastPut(localPath: string, remotePath: string, callback: (err: any) => void): void; + /** + * (Client-only) + * Reads a file in memory and returns its contents + */ + readFile(remotePath: string, options: ReadFileOptions, callback: (err: any, handle: Buffer) => void): void; + + /** + * (Client-only) + * Reads a file in memory and returns its contents + */ + readFile(remotePath: string, encoding: string, callback: (err: any, handle: Buffer) => void): void; + + /** + * (Client-only) + * Reads a file in memory and returns its contents + */ + readFile(remotePath: string, callback: (err: any, handle: Buffer) => void): void; + /** * (Client-only) * Returns a new readable stream for `path`. @@ -1612,6 +1631,11 @@ export interface TransferOptions { step?: (total_transferred: number, chunk: number, total: number) => void; } +export interface ReadFileOptions { + encoding?: string + flag?: string +} + export interface ReadStreamOptions { flags?: string; encoding?: string; diff --git a/types/ssh2/index.d.ts b/types/ssh2/index.d.ts index 25bcfef52e..cf88fff5f1 100644 --- a/types/ssh2/index.d.ts +++ b/types/ssh2/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Qubo // Ron Buckton // Will Boyce +// Lucas Motta // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -21,6 +22,7 @@ import { Attributes, Stats, TransferOptions, + ReadFileOptions, ReadStreamOptions, WriteStreamOptions, FileEntry @@ -1273,6 +1275,24 @@ export interface SFTPWrapper extends events.EventEmitter { */ fastPut(localPath: string, remotePath: string, callback: (err: any) => void): void; + /** + * (Client-only) + * Reads a file in memory and returns its contents + */ + readFile(remotePath: string, options: ReadFileOptions, callback: (err: any, handle: Buffer) => void): void; + + /** + * (Client-only) + * Reads a file in memory and returns its contents + */ + readFile(remotePath: string, encoding: string, callback: (err: any, handle: Buffer) => void): void; + + /** + * (Client-only) + * Reads a file in memory and returns its contents + */ + readFile(remotePath: string, callback: (err: any, handle: Buffer) => void): void; + /** * (Client-only) * Returns a new readable stream for `path`. From f857ba9d66d2f430fb2ff06b7e4579fbf61b7673 Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Wed, 28 Nov 2018 11:17:01 -0500 Subject: [PATCH 171/792] Added CollationDocument type in a couple places that were missed --- types/mongodb/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index a217b0a605..3de97daf60 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -526,7 +526,7 @@ export interface CollectionCreateOptions extends CommonOptions { indexOptionDefaults?: object; viewOn?: string; pipeline?: any[]; - collation?: object; + collation?: CollationDocument; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#collection */ @@ -563,7 +563,7 @@ export interface IndexOptions extends CommonOptions { name?: string; // Creates a partial index based on the given filter object (MongoDB 3.2 or higher) partialFilterExpression?: any; - collation?: Object; + collation?: CollationDocument; default_language?: string } From b2133e941c8646b7a5c0581453123054314c2602 Mon Sep 17 00:00:00 2001 From: Lucas Motta Date: Wed, 28 Nov 2018 16:26:08 +0000 Subject: [PATCH 172/792] Fix credit name --- types/ssh2-streams/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ssh2-streams/index.d.ts b/types/ssh2-streams/index.d.ts index 3eaca56f6f..e80e529ced 100644 --- a/types/ssh2-streams/index.d.ts +++ b/types/ssh2-streams/index.d.ts @@ -1,7 +1,7 @@ // Type definitions for ssh2-streams v0.1.9 // Project: https://github.com/mscdex/ssh2-streams // Definitions by: Ron Buckton -// Definitions by: Ron Buckton +// Definitions by: Lucas Motta // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From 5cc01bba1447d578d0c0c8b4fe80d599638b9dc0 Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Wed, 28 Nov 2018 11:37:45 -0500 Subject: [PATCH 173/792] Fixed incorrect type for caseFirst in CollationDocument --- types/mongodb/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 3de97daf60..ef7b7768d8 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -1786,7 +1786,7 @@ export interface CollationDocument { locale: string; strength?: number; caseLevel?: boolean; - caseFirst?: boolean; + caseFirst?: string; numericOrdering?: boolean; alternate?: string; maxVariable?: string; From 281331fa0b1fc3b9e24b486839f5a22094f230bd Mon Sep 17 00:00:00 2001 From: Konstantin Vasilev Date: Wed, 28 Nov 2018 19:54:03 +0300 Subject: [PATCH 174/792] add typings for dom-helpers module --- types/dom-helpers/activeElement.d.ts | 6 + types/dom-helpers/class/addClass.d.ts | 2 + types/dom-helpers/class/hasClass.d.ts | 2 + types/dom-helpers/class/index.d.ts | 19 ++++ types/dom-helpers/class/removeClass.d.ts | 2 + types/dom-helpers/dom-helpers-tests.ts | 105 ++++++++++++++++++ types/dom-helpers/events/filter.d.ts | 6 + types/dom-helpers/events/index.d.ts | 22 ++++ types/dom-helpers/events/listen.d.ts | 5 + types/dom-helpers/events/off.d.ts | 5 + types/dom-helpers/events/on.d.ts | 5 + types/dom-helpers/index.d.ts | 34 ++++++ types/dom-helpers/ownerDocument.d.ts | 6 + types/dom-helpers/ownerWindow.d.ts | 6 + types/dom-helpers/query/closest.d.ts | 7 ++ types/dom-helpers/query/contains.d.ts | 2 + types/dom-helpers/query/height.d.ts | 2 + types/dom-helpers/query/index.d.ts | 43 +++++++ types/dom-helpers/query/isWindow.d.ts | 2 + types/dom-helpers/query/matches.d.ts | 5 + types/dom-helpers/query/offset.d.ts | 11 ++ types/dom-helpers/query/offsetParent.d.ts | 5 + types/dom-helpers/query/position.d.ts | 7 ++ types/dom-helpers/query/querySelectorAll.d.ts | 8 ++ types/dom-helpers/query/scrollLeft.d.ts | 5 + types/dom-helpers/query/scrollParent.d.ts | 2 + types/dom-helpers/query/scrollTop.d.ts | 6 + types/dom-helpers/query/width.d.ts | 2 + types/dom-helpers/style/getComputedStyle.d.ts | 4 + types/dom-helpers/style/index.d.ts | 9 ++ types/dom-helpers/style/removeStyle.d.ts | 2 + types/dom-helpers/transition/animate.d.ts | 23 ++++ types/dom-helpers/transition/end.d.ts | 12 ++ types/dom-helpers/transition/index.d.ts | 16 +++ types/dom-helpers/transition/properties.d.ts | 26 +++++ types/dom-helpers/tsconfig.json | 60 ++++++++++ types/dom-helpers/tslint.json | 6 + .../util/requestAnimationFrame.d.ts | 11 ++ types/dom-helpers/util/scrollTo.d.ts | 3 + types/dom-helpers/util/scrollbarSize.d.ts | 6 + 40 files changed, 510 insertions(+) create mode 100644 types/dom-helpers/activeElement.d.ts create mode 100644 types/dom-helpers/class/addClass.d.ts create mode 100644 types/dom-helpers/class/hasClass.d.ts create mode 100644 types/dom-helpers/class/index.d.ts create mode 100644 types/dom-helpers/class/removeClass.d.ts create mode 100644 types/dom-helpers/dom-helpers-tests.ts create mode 100644 types/dom-helpers/events/filter.d.ts create mode 100644 types/dom-helpers/events/index.d.ts create mode 100644 types/dom-helpers/events/listen.d.ts create mode 100644 types/dom-helpers/events/off.d.ts create mode 100644 types/dom-helpers/events/on.d.ts create mode 100644 types/dom-helpers/index.d.ts create mode 100644 types/dom-helpers/ownerDocument.d.ts create mode 100644 types/dom-helpers/ownerWindow.d.ts create mode 100644 types/dom-helpers/query/closest.d.ts create mode 100644 types/dom-helpers/query/contains.d.ts create mode 100644 types/dom-helpers/query/height.d.ts create mode 100644 types/dom-helpers/query/index.d.ts create mode 100644 types/dom-helpers/query/isWindow.d.ts create mode 100644 types/dom-helpers/query/matches.d.ts create mode 100644 types/dom-helpers/query/offset.d.ts create mode 100644 types/dom-helpers/query/offsetParent.d.ts create mode 100644 types/dom-helpers/query/position.d.ts create mode 100644 types/dom-helpers/query/querySelectorAll.d.ts create mode 100644 types/dom-helpers/query/scrollLeft.d.ts create mode 100644 types/dom-helpers/query/scrollParent.d.ts create mode 100644 types/dom-helpers/query/scrollTop.d.ts create mode 100644 types/dom-helpers/query/width.d.ts create mode 100644 types/dom-helpers/style/getComputedStyle.d.ts create mode 100644 types/dom-helpers/style/index.d.ts create mode 100644 types/dom-helpers/style/removeStyle.d.ts create mode 100644 types/dom-helpers/transition/animate.d.ts create mode 100644 types/dom-helpers/transition/end.d.ts create mode 100644 types/dom-helpers/transition/index.d.ts create mode 100644 types/dom-helpers/transition/properties.d.ts create mode 100644 types/dom-helpers/tsconfig.json create mode 100644 types/dom-helpers/tslint.json create mode 100644 types/dom-helpers/util/requestAnimationFrame.d.ts create mode 100644 types/dom-helpers/util/scrollTo.d.ts create mode 100644 types/dom-helpers/util/scrollbarSize.d.ts diff --git a/types/dom-helpers/activeElement.d.ts b/types/dom-helpers/activeElement.d.ts new file mode 100644 index 0000000000..3a964f0479 --- /dev/null +++ b/types/dom-helpers/activeElement.d.ts @@ -0,0 +1,6 @@ +/** + * Returns focused element safely + */ +declare const activeElement: (doc?: Document) => Element; + +export = activeElement; diff --git a/types/dom-helpers/class/addClass.d.ts b/types/dom-helpers/class/addClass.d.ts new file mode 100644 index 0000000000..5431a9d256 --- /dev/null +++ b/types/dom-helpers/class/addClass.d.ts @@ -0,0 +1,2 @@ +declare const addClass: (element: Element, className: string) => void; +export = addClass; diff --git a/types/dom-helpers/class/hasClass.d.ts b/types/dom-helpers/class/hasClass.d.ts new file mode 100644 index 0000000000..2ec83c8a2f --- /dev/null +++ b/types/dom-helpers/class/hasClass.d.ts @@ -0,0 +1,2 @@ +declare const hasClass: (element: Element, className: string) => boolean; +export = hasClass; diff --git a/types/dom-helpers/class/index.d.ts b/types/dom-helpers/class/index.d.ts new file mode 100644 index 0000000000..24b0dbd1e6 --- /dev/null +++ b/types/dom-helpers/class/index.d.ts @@ -0,0 +1,19 @@ +import * as addClass from "./addClass"; +import * as removeClass from "./removeClass"; +import * as hasClass from "./hasClass"; + +declare const _default: { + addClass: typeof addClass; + removeClass: typeof removeClass; + hasClass: typeof hasClass; +}; + +declare const _export: { + addClass: typeof addClass; + removeClass: typeof removeClass; + hasClass: typeof hasClass; + + default: typeof _export; +}; + +export = _export; diff --git a/types/dom-helpers/class/removeClass.d.ts b/types/dom-helpers/class/removeClass.d.ts new file mode 100644 index 0000000000..a67929344f --- /dev/null +++ b/types/dom-helpers/class/removeClass.d.ts @@ -0,0 +1,2 @@ +declare const removeClass: (element: Element, className: string) => void; +export = removeClass; diff --git a/types/dom-helpers/dom-helpers-tests.ts b/types/dom-helpers/dom-helpers-tests.ts new file mode 100644 index 0000000000..60266ae725 --- /dev/null +++ b/types/dom-helpers/dom-helpers-tests.ts @@ -0,0 +1,105 @@ +import * as helpers from "dom-helpers"; +import * as ownerDocument from "dom-helpers/ownerDocument"; +import * as ownerWindow from "dom-helpers/ownerWindow"; +import * as activeElement from "dom-helpers/activeElement"; + +import * as classes from "dom-helpers/class"; +import * as hasClass from "dom-helpers/class/hasClass"; +import * as removeClass from "dom-helpers/class/removeClass"; +import * as addClass from "dom-helpers/class/addClass"; + +import * as events from "dom-helpers/events"; +import * as on from "dom-helpers/events/on"; +import * as off from "dom-helpers/events/off"; +import * as listen from "dom-helpers/events/listen"; +import * as filter from "dom-helpers/events/filter"; + +import * as query from "dom-helpers/query"; +import * as matches from "dom-helpers/query/matches"; +import * as height from "dom-helpers/query/height"; +import * as width from "dom-helpers/query/width"; +import * as offset from "dom-helpers/query/offset"; +import * as offsetParent from "dom-helpers/query/offsetParent"; +import * as position from "dom-helpers/query/position"; +import * as contains from "dom-helpers/query/contains"; +import * as scrollParent from "dom-helpers/query/scrollParent"; +import * as scrollTop from "dom-helpers/query/scrollTop"; +import * as querySelectorAll from "dom-helpers/query/querySelectorAll"; +import * as closest from "dom-helpers/query/closest"; + +import * as css from "dom-helpers/style"; +import * as getComputedStyle from "dom-helpers/style/getComputedStyle"; +import * as removeStyle from "dom-helpers/style/removeStyle"; + +import * as transition from "dom-helpers/transition"; +import * as end from "dom-helpers/transition/end"; +import * as properties from "dom-helpers/transition/properties"; + +const element = helpers.activeElement() || activeElement(); +const win = + helpers.ownerWindow(element || null || undefined) || + ownerWindow(element || null || undefined); +const doc = helpers.ownerDocument(element) || ownerDocument(element); +const id = helpers.requestAnimationFrame(() => {}); +helpers.requestAnimationFrame.cancel(id); + +const padding: string = css(element, "padding"); +css(element, "padding", 10); +css(element, "padding", "12px"); + +events.on(element, "click", () => {}); +on(element, "click", () => {}); +events.off(element, "click", () => {}, true); +off(element, "click", () => {}, true); +events.listen(element, "click", () => {})(); +listen(element, "click", () => {})(); +events.on(element, "click", filter("div > a", () => {})); +on(element, "click", events.filter("div > a", () => {})); + +classes.addClass(element, "class"); +classes.removeClass(element, "class"); +classes.hasClass(element, "class"); + +addClass(element, "class"); +removeClass(element, "class"); +hasClass(element, "class"); + +const match: boolean = + query.matches(element, ".class") || matches(element, ".class"); +const h: number = query.height(element) || height(element); +const w: number = query.width(element) || width(element); +const _offset: { top: number; left: number; bottom: number; right: number } = + query.offset(element) || offset(element); +const _offsetParent: Element = + query.offsetParent(element) || offsetParent(element); +const _position: { top: number; left: number; bottom: number; right: number } = + query.position(element) || position(element); +const _contains: boolean = + query.contains(element, element) || contains(element, element); +const _scrollParent: Element = + query.scrollParent(element) || scrollParent(element); +const _scrollTop: number = query.scrollTop(element) || scrollTop(element); +query.scrollTop(element, 100); +scrollTop(element, 100); +const _querySelectorAll: HTMLElement[] = + (query.querySelectorAll(element, "*") as HTMLElement[]) || + (querySelectorAll(element, "*") as HTMLElement[]); +const _closest: Element = + query.closest(element, "*", element) || closest(element, "*", element); + +const _getComputedStyle: string = getComputedStyle(element).getPropertyValue( + "padding" +); +removeStyle(element, "padding"); + +transition.end(element, (event) => { + const currentTarget: Element = event.currentTarget; + const target: Element = event.target; +}, 100); + +end(element, (event) => { + const currentTarget: Element = event.currentTarget; + const target: Element = event.target; +}, 100); + +const transform: string = properties.transform; diff --git a/types/dom-helpers/events/filter.d.ts b/types/dom-helpers/events/filter.d.ts new file mode 100644 index 0000000000..fa54287155 --- /dev/null +++ b/types/dom-helpers/events/filter.d.ts @@ -0,0 +1,6 @@ +/** + * Returns a function handler that only fires when the target matches or is contained in the selector + * @example events.on(list, 'click', events.filter('li > a', handler)) + */ +declare const filter: (selector: string, listener: EventListener) => EventListener; +export = filter; diff --git a/types/dom-helpers/events/index.d.ts b/types/dom-helpers/events/index.d.ts new file mode 100644 index 0000000000..fb2e5e89c7 --- /dev/null +++ b/types/dom-helpers/events/index.d.ts @@ -0,0 +1,22 @@ +import * as on from './on'; +import * as off from './off'; +import * as listen from './listen'; +import * as filter from './filter'; + +declare const _default: { + on: typeof on; + off: typeof off; + listen: typeof listen; + filter: typeof filter; +}; + +declare const _export: { + on: typeof on; + off: typeof off; + listen: typeof listen; + filter: typeof filter; + + default: typeof _default; +}; + +export = _export; diff --git a/types/dom-helpers/events/listen.d.ts b/types/dom-helpers/events/listen.d.ts new file mode 100644 index 0000000000..ec12d5c0e3 --- /dev/null +++ b/types/dom-helpers/events/listen.d.ts @@ -0,0 +1,5 @@ +/** + * Wraps on and returns a function that calls off for you + */ +declare const listen: (element: Element, type: string, listener: EventListener, capture?: boolean) => () => void; +export = listen; diff --git a/types/dom-helpers/events/off.d.ts b/types/dom-helpers/events/off.d.ts new file mode 100644 index 0000000000..32699cb8a4 --- /dev/null +++ b/types/dom-helpers/events/off.d.ts @@ -0,0 +1,5 @@ +/** + * Capture is silently ignored in ie8 + */ +declare const off: (element: Element, type: string, listener: EventListener, capture?: boolean) => void; +export = off; diff --git a/types/dom-helpers/events/on.d.ts b/types/dom-helpers/events/on.d.ts new file mode 100644 index 0000000000..2028d70af6 --- /dev/null +++ b/types/dom-helpers/events/on.d.ts @@ -0,0 +1,5 @@ +/** + * Capture is silently ignored in ie8 + */ +declare const on: (element: Element, type: string, listener: EventListener, capture?: boolean) => void; +export = on; diff --git a/types/dom-helpers/index.d.ts b/types/dom-helpers/index.d.ts new file mode 100644 index 0000000000..3215fcc500 --- /dev/null +++ b/types/dom-helpers/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for dom-helpers 3.4 +// Project: https://github.com/react-bootstrap/dom-helpers +// Definitions by: Konstantin Vasiliev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { default as events } from "./events"; +import { default as query } from "./query"; +import * as style from "./style"; +import * as activeElement from "./activeElement"; +import * as ownerDocument from "./ownerDocument"; +import * as ownerWindow from "./ownerWindow"; +import * as requestAnimationFrame from "./util/requestAnimationFrame"; + +declare const _default: typeof events & + typeof query & { + style: typeof style; + activeElement: typeof activeElement; + ownerDocument: typeof ownerDocument; + ownerWindow: typeof ownerWindow; + requestAnimationFrame: typeof requestAnimationFrame; + }; + +declare const _export: { + style: typeof style; + activeElement: typeof activeElement; + ownerDocument: typeof ownerDocument; + ownerWindow: typeof ownerWindow; + requestAnimationFrame: typeof requestAnimationFrame; + + default: typeof _default; +}; + +export = _export; diff --git a/types/dom-helpers/ownerDocument.d.ts b/types/dom-helpers/ownerDocument.d.ts new file mode 100644 index 0000000000..248981141c --- /dev/null +++ b/types/dom-helpers/ownerDocument.d.ts @@ -0,0 +1,6 @@ +/** + * Returns the element's document owner + */ +declare const ownerDocument: (node?: Node | null) => Document; + +export = ownerDocument; diff --git a/types/dom-helpers/ownerWindow.d.ts b/types/dom-helpers/ownerWindow.d.ts new file mode 100644 index 0000000000..f827d3f073 --- /dev/null +++ b/types/dom-helpers/ownerWindow.d.ts @@ -0,0 +1,6 @@ +/** + * Returns the element's document window + */ +declare const ownerWindow: (node?: Node | null) => Window; + +export = ownerWindow; diff --git a/types/dom-helpers/query/closest.d.ts b/types/dom-helpers/query/closest.d.ts new file mode 100644 index 0000000000..5076d3bdf2 --- /dev/null +++ b/types/dom-helpers/query/closest.d.ts @@ -0,0 +1,7 @@ +declare const closest: ( + element: Element, + selector: string, + context: Element +) => Element; + +export = closest; diff --git a/types/dom-helpers/query/contains.d.ts b/types/dom-helpers/query/contains.d.ts new file mode 100644 index 0000000000..d5e03884aa --- /dev/null +++ b/types/dom-helpers/query/contains.d.ts @@ -0,0 +1,2 @@ +declare const contains: (context: Node, node: Node) => boolean; +export = contains; diff --git a/types/dom-helpers/query/height.d.ts b/types/dom-helpers/query/height.d.ts new file mode 100644 index 0000000000..807a3a0782 --- /dev/null +++ b/types/dom-helpers/query/height.d.ts @@ -0,0 +1,2 @@ +declare const height: (element: Element, useClientHeight?: boolean) => number; +export = height; diff --git a/types/dom-helpers/query/index.d.ts b/types/dom-helpers/query/index.d.ts new file mode 100644 index 0000000000..b0dff78ac1 --- /dev/null +++ b/types/dom-helpers/query/index.d.ts @@ -0,0 +1,43 @@ +import * as matches from "./matches"; +import * as height from "./height"; +import * as width from "./width"; +import * as offset from "./offset"; +import * as offsetParent from "./offsetParent"; +import * as position from "./position"; +import * as contains from "./contains"; +import * as scrollParent from "./scrollParent"; +import * as scrollTop from "./scrollTop"; +import * as querySelectorAll from "./querySelectorAll"; +import * as closest from "./closest"; + +declare const _default: { + matches: typeof matches; + height: typeof height; + width: typeof width; + offset: typeof offset; + offsetParent: typeof offsetParent; + position: typeof position; + contains: typeof contains; + scrollParent: typeof scrollParent; + scrollTop: typeof scrollTop; + querySelectorAll: typeof querySelectorAll; + closest: typeof closest; +}; + +declare const _export: { + matches: typeof matches; + height: typeof height; + width: typeof width; + offset: typeof offset; + offsetParent: typeof offsetParent; + position: typeof position; + contains: typeof contains; + scrollParent: typeof scrollParent; + scrollTop: typeof scrollTop; + querySelectorAll: typeof querySelectorAll; + closest: typeof closest; + + default: typeof _default; +}; + +export = _export; diff --git a/types/dom-helpers/query/isWindow.d.ts b/types/dom-helpers/query/isWindow.d.ts new file mode 100644 index 0000000000..e8e0c96534 --- /dev/null +++ b/types/dom-helpers/query/isWindow.d.ts @@ -0,0 +1,2 @@ +declare const isWindow: (node: any) => boolean; +export = isWindow; diff --git a/types/dom-helpers/query/matches.d.ts b/types/dom-helpers/query/matches.d.ts new file mode 100644 index 0000000000..709845bc61 --- /dev/null +++ b/types/dom-helpers/query/matches.d.ts @@ -0,0 +1,5 @@ +/** + * `matches()` polyfill that works in ie8 + */ +declare const matches: (element: Element, selectors: string) => boolean; +export = matches; diff --git a/types/dom-helpers/query/offset.d.ts b/types/dom-helpers/query/offset.d.ts new file mode 100644 index 0000000000..2b41598076 --- /dev/null +++ b/types/dom-helpers/query/offset.d.ts @@ -0,0 +1,11 @@ +declare namespace DomHelpersOffset { + interface DomHelpersRect { + bottom: number; + left: number; + right: number; + top: number; + } +} + +declare const DomHelpersOffset: (element: Element) => DomHelpersOffset.DomHelpersRect; +export = DomHelpersOffset; diff --git a/types/dom-helpers/query/offsetParent.d.ts b/types/dom-helpers/query/offsetParent.d.ts new file mode 100644 index 0000000000..ecdfeb9d71 --- /dev/null +++ b/types/dom-helpers/query/offsetParent.d.ts @@ -0,0 +1,5 @@ +/** + * Returns the parent node that the element is offset from + */ +declare const offsetParent: (element: Element) => Element; +export = offsetParent; diff --git a/types/dom-helpers/query/position.d.ts b/types/dom-helpers/query/position.d.ts new file mode 100644 index 0000000000..5f683f97e1 --- /dev/null +++ b/types/dom-helpers/query/position.d.ts @@ -0,0 +1,7 @@ +import { DomHelpersRect } from "./offset"; +/** + * Return "offset" of the node to its offsetParent, + * optionally you can specify the offset parent if different than the "real" one + */ +declare const position: (element: Element, offsetParent?: Node) => DomHelpersRect; +export = position; diff --git a/types/dom-helpers/query/querySelectorAll.d.ts b/types/dom-helpers/query/querySelectorAll.d.ts new file mode 100644 index 0000000000..21c256adfc --- /dev/null +++ b/types/dom-helpers/query/querySelectorAll.d.ts @@ -0,0 +1,8 @@ +/** + * Optimized qsa, uses `getElementBy{Id|TagName|ClassName}` if it can + */ +declare const querySelectorAll: ( + element: Element, + selector: string +) => Element[]; +export = querySelectorAll; diff --git a/types/dom-helpers/query/scrollLeft.d.ts b/types/dom-helpers/query/scrollLeft.d.ts new file mode 100644 index 0000000000..3a0c0a3fa3 --- /dev/null +++ b/types/dom-helpers/query/scrollLeft.d.ts @@ -0,0 +1,5 @@ +declare function _scrollLeft(element: Element): number; +declare function _scrollLeft(element: Element, value: number): void; + +declare const scrollLeft: typeof _scrollLeft; +export = scrollLeft; diff --git a/types/dom-helpers/query/scrollParent.d.ts b/types/dom-helpers/query/scrollParent.d.ts new file mode 100644 index 0000000000..f104f68bd3 --- /dev/null +++ b/types/dom-helpers/query/scrollParent.d.ts @@ -0,0 +1,2 @@ +declare const scrollParent: (element: Element) => Element; +export = scrollParent; diff --git a/types/dom-helpers/query/scrollTop.d.ts b/types/dom-helpers/query/scrollTop.d.ts new file mode 100644 index 0000000000..d56d9d17e1 --- /dev/null +++ b/types/dom-helpers/query/scrollTop.d.ts @@ -0,0 +1,6 @@ +declare function _scrollTop(element: Element): number; +declare function _scrollTop(element: Element, value: number): void; + +declare const scrollTop: typeof _scrollTop; + +export = scrollTop; diff --git a/types/dom-helpers/query/width.d.ts b/types/dom-helpers/query/width.d.ts new file mode 100644 index 0000000000..4b4fd15bb5 --- /dev/null +++ b/types/dom-helpers/query/width.d.ts @@ -0,0 +1,2 @@ +declare const width: (element: Element, useClientWidth?: boolean) => number; +export = width; diff --git a/types/dom-helpers/style/getComputedStyle.d.ts b/types/dom-helpers/style/getComputedStyle.d.ts new file mode 100644 index 0000000000..c8be2d3976 --- /dev/null +++ b/types/dom-helpers/style/getComputedStyle.d.ts @@ -0,0 +1,4 @@ +declare const getComputedStyle: ( + element: Element +) => { getPropertyValue: (prop: string) => string }; +export = getComputedStyle; diff --git a/types/dom-helpers/style/index.d.ts b/types/dom-helpers/style/index.d.ts new file mode 100644 index 0000000000..2cb8844194 --- /dev/null +++ b/types/dom-helpers/style/index.d.ts @@ -0,0 +1,9 @@ +declare function _style(element: Element, property: string): string; +declare function _style( + element: Element, + property: string | { [key: string]: any }, + value: any +): void; + +declare const style: typeof _style; +export = style; diff --git a/types/dom-helpers/style/removeStyle.d.ts b/types/dom-helpers/style/removeStyle.d.ts new file mode 100644 index 0000000000..4ccdcae438 --- /dev/null +++ b/types/dom-helpers/style/removeStyle.d.ts @@ -0,0 +1,2 @@ +declare const removeStyle: (element: Element, key: string) => void; +export = removeStyle; diff --git a/types/dom-helpers/transition/animate.d.ts b/types/dom-helpers/transition/animate.d.ts new file mode 100644 index 0000000000..9cd71843e5 --- /dev/null +++ b/types/dom-helpers/transition/animate.d.ts @@ -0,0 +1,23 @@ +interface DomHelpersAnimationArgs { + element: Element; + properties: { [key: string]: any }; + duration?: number; + easing?: boolean; + callback?: () => void; +} + +/** + * Programmatically start css transitions + */ +declare function _animate(args: DomHelpersAnimationArgs): { cancel: () => void }; +declare function _animate( + element: Element, + properties: { [key: string]: any }, + duration?: number, + easing?: boolean, + callback?: () => void +): { cancel: () => void }; + +declare const animate: typeof _animate; + +export = animate; diff --git a/types/dom-helpers/transition/end.d.ts b/types/dom-helpers/transition/end.d.ts new file mode 100644 index 0000000000..5b662395e4 --- /dev/null +++ b/types/dom-helpers/transition/end.d.ts @@ -0,0 +1,12 @@ +/** + * Listens for transition end, and ensures that the handler if called + * even if the transition fails to fire its end event. + * Will attempt to read duration from the element, otherwise one can be provided + */ +declare const end: ( + element: T, + handler: (event: { target: T, currentTarget: T }) => void, + duration?: number +) => void; + +export = end; diff --git a/types/dom-helpers/transition/index.d.ts b/types/dom-helpers/transition/index.d.ts new file mode 100644 index 0000000000..28b1ce9eb0 --- /dev/null +++ b/types/dom-helpers/transition/index.d.ts @@ -0,0 +1,16 @@ +import * as end from "./end"; +import * as properties from "./properties"; + +declare const _default: { + end: typeof end; + properties: typeof properties; +}; + +declare const _export: { + end: typeof end; + properties: typeof properties; + + default: typeof _default; +}; + +export = _export; diff --git a/types/dom-helpers/transition/properties.d.ts b/types/dom-helpers/transition/properties.d.ts new file mode 100644 index 0000000000..4049c19982 --- /dev/null +++ b/types/dom-helpers/transition/properties.d.ts @@ -0,0 +1,26 @@ +declare const _default: { + transform: string; + end: string; + property: string; + timing: string; + delay: string; + duration: string; +}; + +declare const _export: { + transform: string; + transitionProperty: string; + transitionTiming: string; + transitionDelay: string; + transitionDuration: string; + transitionEnd: string; + animationName: string; + animationDuration: string; + animationTiming: string; + animationDelay: string; + animationEnd: string; + + default: typeof _default, +}; + +export = _export; diff --git a/types/dom-helpers/tsconfig.json b/types/dom-helpers/tsconfig.json new file mode 100644 index 0000000000..bbaca98dbe --- /dev/null +++ b/types/dom-helpers/tsconfig.json @@ -0,0 +1,60 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "activeElement.d.ts", + "ownerDocument.d.ts", + "ownerWindow.d.ts", + "dom-helpers-tests.ts", + "class/addClass.d.ts", + "class/hasClass.d.ts", + "class/index.d.ts", + "class/removeClass.d.ts", + "events/filter.d.ts", + "events/index.d.ts", + "events/listen.d.ts", + "events/off.d.ts", + "events/on.d.ts", + "query/closest.d.ts", + "query/contains.d.ts", + "query/height.d.ts", + "query/index.d.ts", + "query/isWindow.d.ts", + "query/matches.d.ts", + "query/offset.d.ts", + "query/offsetParent.d.ts", + "query/position.d.ts", + "query/querySelectorAll.d.ts", + "query/scrollLeft.d.ts", + "query/scrollParent.d.ts", + "query/scrollTop.d.ts", + "query/width.d.ts", + "style/getComputedStyle.d.ts", + "style/index.d.ts", + "style/removeStyle.d.ts", + "transition/animate.d.ts", + "transition/end.d.ts", + "transition/index.d.ts", + "transition/properties.d.ts", + "util/requestAnimationFrame.d.ts", + "util/scrollbarSize.d.ts", + "util/scrollTo.d.ts" + ] +} diff --git a/types/dom-helpers/tslint.json b/types/dom-helpers/tslint.json new file mode 100644 index 0000000000..2d469ebdbd --- /dev/null +++ b/types/dom-helpers/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "prefer-declare-function": false + } +} diff --git a/types/dom-helpers/util/requestAnimationFrame.d.ts b/types/dom-helpers/util/requestAnimationFrame.d.ts new file mode 100644 index 0000000000..211fb7486f --- /dev/null +++ b/types/dom-helpers/util/requestAnimationFrame.d.ts @@ -0,0 +1,11 @@ +interface DomHelpersRaf { + /** + * Returns an ID for canceling + */ + (callback: () => void): number; + cancel: (id: number) => void; +} + +declare const requestAnimationFrame: DomHelpersRaf; + +export = requestAnimationFrame; diff --git a/types/dom-helpers/util/scrollTo.d.ts b/types/dom-helpers/util/scrollTo.d.ts new file mode 100644 index 0000000000..b336c1104a --- /dev/null +++ b/types/dom-helpers/util/scrollTo.d.ts @@ -0,0 +1,3 @@ +declare const scrollTo: (element: Element, scrollParent?: Element) => () => void; + +export = scrollTo; diff --git a/types/dom-helpers/util/scrollbarSize.d.ts b/types/dom-helpers/util/scrollbarSize.d.ts new file mode 100644 index 0000000000..67d6c840e2 --- /dev/null +++ b/types/dom-helpers/util/scrollbarSize.d.ts @@ -0,0 +1,6 @@ +/** + * Returns the scrollbar's width size in pixels + */ +declare const scrollbarSize: (recalc?: boolean) => number; + +export = scrollbarSize; From 64e8c6d752ddc75d26fcfed5478e2b5eb0a863f4 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 28 Nov 2018 19:36:59 +0100 Subject: [PATCH 175/792] Add types for timing-safe-equal --- types/timing-safe-equal/index.d.ts | 10 ++++++++ .../timing-safe-equal-tests.ts | 5 ++++ types/timing-safe-equal/tsconfig.json | 23 +++++++++++++++++++ types/timing-safe-equal/tslint.json | 1 + 4 files changed, 39 insertions(+) create mode 100644 types/timing-safe-equal/index.d.ts create mode 100644 types/timing-safe-equal/timing-safe-equal-tests.ts create mode 100644 types/timing-safe-equal/tsconfig.json create mode 100644 types/timing-safe-equal/tslint.json diff --git a/types/timing-safe-equal/index.d.ts b/types/timing-safe-equal/index.d.ts new file mode 100644 index 0000000000..e1bf8f16d8 --- /dev/null +++ b/types/timing-safe-equal/index.d.ts @@ -0,0 +1,10 @@ +// Type definitions for timing-safe-equal 1.0 +// Project: https://github.com/crypto-browserify/timing-safe-equal +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export = timingSafeEqual; + +declare function timingSafeEqual(a: Buffer, b: Buffer): boolean; diff --git a/types/timing-safe-equal/timing-safe-equal-tests.ts b/types/timing-safe-equal/timing-safe-equal-tests.ts new file mode 100644 index 0000000000..cc8069de3b --- /dev/null +++ b/types/timing-safe-equal/timing-safe-equal-tests.ts @@ -0,0 +1,5 @@ +import timingSafeEqual = require('timing-safe-equal'); + +const buffer: Buffer = new Buffer([1, 2, 3, 4, 5]); +// $ExpectType boolean +timingSafeEqual(buffer, buffer); diff --git a/types/timing-safe-equal/tsconfig.json b/types/timing-safe-equal/tsconfig.json new file mode 100644 index 0000000000..f12ec7b09e --- /dev/null +++ b/types/timing-safe-equal/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "timing-safe-equal-tests.ts" + ] +} diff --git a/types/timing-safe-equal/tslint.json b/types/timing-safe-equal/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/timing-safe-equal/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 01972623953bfefc9378b829bf1afd21a550d504 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 28 Nov 2018 20:27:35 +0100 Subject: [PATCH 176/792] Add types for diffie-hellman --- types/diffie-hellman/diffie-hellman-tests.ts | 48 ++++++++++++++++++++ types/diffie-hellman/index.d.ts | 8 ++++ types/diffie-hellman/tsconfig.json | 23 ++++++++++ types/diffie-hellman/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 types/diffie-hellman/diffie-hellman-tests.ts create mode 100644 types/diffie-hellman/index.d.ts create mode 100644 types/diffie-hellman/tsconfig.json create mode 100644 types/diffie-hellman/tslint.json diff --git a/types/diffie-hellman/diffie-hellman-tests.ts b/types/diffie-hellman/diffie-hellman-tests.ts new file mode 100644 index 0000000000..645ebc23bd --- /dev/null +++ b/types/diffie-hellman/diffie-hellman-tests.ts @@ -0,0 +1,48 @@ +import * as dh from 'diffie-hellman'; + +const dh1 = dh.getDiffieHellman('modp1'); +// $ExpectType DiffieHellman +dh1; +// $ExpectType Buffer +dh1.generateKeys(); +// $ExpectType string +dh1.generateKeys('hex'); +// $ExpectType Buffer +dh1.getPrime(); +// $ExpectType string +dh1.getPrime('hex'); +// $ExpectType Buffer +dh1.getGenerator(); +// $ExpectType string +dh1.getGenerator('hex'); +const pk = dh1.getPublicKey(); +// $ExpectType Buffer +pk; +// $ExpectType string +dh1.getPublicKey('hex'); +// $ExpectType Buffer +dh1.getPrivateKey(); +// $ExpectType string +dh1.getPrivateKey('hex'); +// $ExpectType Buffer +dh1.computeSecret(pk); +// $ExpectType Buffer +dh1.computeSecret(pk.toString('hex'), 'hex'); +// $ExpectType string +dh1.computeSecret(pk.toString('hex'), 'hex', 'hex'); + +const dh2 = dh.createDiffieHellman(new Buffer([5])); +// $ExpectType DiffieHellman +dh2; +dh.createDiffieHellman('prime', 'hex'); +dh.createDiffieHellman('prime', 'hex', new Buffer([5])); +dh.createDiffieHellman('prime', 'hex', 5); +dh.createDiffieHellman('prime', 'hex', 'generator', 'hex'); +dh.createDiffieHellman(1); +dh.createDiffieHellman(1, 1); +dh.createDiffieHellman(1, new Buffer([5])); + +dh2.setPublicKey(pk); +dh2.setPublicKey(pk.toString('hex'), 'hex'); +dh2.setPrivateKey(pk); +dh2.setPrivateKey(pk.toString('hex'), 'hex'); diff --git a/types/diffie-hellman/index.d.ts b/types/diffie-hellman/index.d.ts new file mode 100644 index 0000000000..7b59cf9182 --- /dev/null +++ b/types/diffie-hellman/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for diffie-hellman 5.0 +// Project: https://github.com/crypto-browserify/diffie-hellman +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export { createDiffieHellman, getDiffieHellman, DiffieHellman } from 'crypto'; diff --git a/types/diffie-hellman/tsconfig.json b/types/diffie-hellman/tsconfig.json new file mode 100644 index 0000000000..743c9eea4c --- /dev/null +++ b/types/diffie-hellman/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "diffie-hellman-tests.ts" + ] +} diff --git a/types/diffie-hellman/tslint.json b/types/diffie-hellman/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/diffie-hellman/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 850c8337b5a1ccf88a967a69aad34959fcdfaa2a Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 28 Nov 2018 22:57:47 +0100 Subject: [PATCH 177/792] [improve] Improve type of prompts --- types/prompts/index.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index bfb08a8bd7..0db58ea435 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -52,12 +52,12 @@ declare namespace prompts { } interface Options { - onSubmit: (prompt: PromptObject, answer: any, answers: any[]) => void; - onCancel: (prompt: PromptObject, answers: any) => void; + onSubmit?: (prompt: PromptObject, answer: any, answers: any[]) => void; + onCancel?: (prompt: PromptObject, answers: any) => void; } interface PromptObject { - type: ValueOrFunc | Falsy; + type: ValueOrFunc | Falsy; name: ValueOrFunc; message?: ValueOrFunc; initial?: string | number | boolean; @@ -89,5 +89,7 @@ declare namespace prompts { type Falsy = false | null | undefined; + type PromptType = "text" | "password" | "invisible" | "number" | "confirm" | "list" | "toggle" | "select" | "multiselect" | "autocomplete" | Falsy + type ValueOrFunc = T | PrevCaller; } From 47a20469245d7c747192ac25ab769e8d23e2b5ac Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Wed, 28 Nov 2018 18:37:23 -0800 Subject: [PATCH 178/792] Add definitions for jju --- types/jju/index.d.ts | 213 ++++++++++++++++++++++++++++++++++++++++ types/jju/jju-tests.ts | 4 + types/jju/tsconfig.json | 23 +++++ types/jju/tslint.json | 1 + 4 files changed, 241 insertions(+) create mode 100644 types/jju/index.d.ts create mode 100644 types/jju/jju-tests.ts create mode 100644 types/jju/tsconfig.json create mode 100644 types/jju/tslint.json diff --git a/types/jju/index.d.ts b/types/jju/index.d.ts new file mode 100644 index 0000000000..46fbf2f77b --- /dev/null +++ b/types/jju/index.d.ts @@ -0,0 +1,213 @@ +// Type definitions for jju 1.4 +// Project: https://github.com/rlidwka/jju +// Definitions by: Elizabeth Craig +// Alex Kocharin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// Disabling unified-signatures rule so different documentation can be provided for each signature. +// tslint:disable:unified-signatures + +export interface ParseOptions { + /** + * What to do with reserved keys (default 'ignore'). + * - "ignore" - ignore reserved keys + * - "throw" - throw SyntaxError in case of reserved keys + * - "replace" - replace reserved keys, this is the default JSON.parse behaviour, unsafe + */ + reserved_keys?: 'ignore' | 'throw' | 'replace'; + + /** + * Create object as `Object.create(null)` instead of `{}`. + * - If reserved_keys != 'replace', default is false. + * - If reserved_keys == 'replace', default is true. + * + * It is usually unsafe and not recommended to change this option to false in the last case. + */ + null_prototype?: boolean; + + /** + * Reviver function (follows the JSON spec). This function is called for each member of the object. + * If a member contains nested objects, the nested objects are transformed before the parent object is. + */ + reviver?: (key: any, value: any) => any; + + /** + * Operation mode (default 'json5'). Set to 'json' if you want to throw on non-strict json files. + */ + mode?: 'json5' | 'json' | 'cjson'; +} + +export interface StringifyOptions { + /** + * Output ascii only (default false). + * If this option is enabled, output will not have any characters except 0x20-0x7f. + */ + ascii?: boolean; + + /** + * This option follows JSON specification. + * @default '\t' + */ + indent?: string | number | boolean; + + /** + * Enquoting char. + * - If `mode` is 'json', default is " + * - Otherwise, default is ' + */ + quote?: '"' | "'"; + + /** + * Whether keys quoting in objects is required or not. + * If you want `{"q": 1}` instead of `{q: 1}`, set it to true. + * - If `mode` is 'json', default is true + * - Otherwise, default is false + */ + quote_keys?: boolean; + + /** + * Sort all keys while stringifying. + * By default sort order will depend on implementation--with v8 it's insertion order. + * If set to true, all keys (but not arrays) will be sorted alphabetically. + * You can provide your own sorting function as well. + * @default false + */ + sort_keys?: boolean | ((a: any, b: any) => number); + + /** + * Replacer function or array. This option follows JSON specification. + * If a function, used to transform the results. + * If an array, acts as a approved list for selecting the object properties that will be stringified. + */ + replacer?: ((key: string, value: any) => any) | Array; + + /** + * Don't output trailing comma. If this option is set, arrays like `[1,2,3,]` will never be generated. + * Otherwise they may be generated for pretty printing. + * - If `mode` is JSON, default is true + * - Otherwise, default is false + */ + no_trailing_comma?: boolean; + + /** + * Operation mode. Set it to 'json' if you want correct json in the output. + * If it is 'json', following options are implied: + * - options.quote = '"' + * - options.no_trailing_comma = true + * - options.quote_keys = true + * - '\x' literals are not used + */ + mode?: 'json' | 'json5' | 'cjson'; +} + +/** + * Represents a token in a JSON file. + */ +export interface Token { + /** Raw text of this token. If you join all raws, you will get the original document. */ + raw: string; + /** Type of the token. */ + type: 'whitespace' | 'comment' | 'key' | 'literal' | 'separator' | 'newline'; + /** Path to the current token in the syntax tree. */ + stack: string[]; + /** Value of the token if token is a key or literal. */ + value?: any; +} + +/** + * Object defining a programming style in which the JSON document was written. + */ +export interface JsonStyle { + /** Preferred indentation. */ + indent: string; + /** Preferred newline. */ + newline: string; + /** " or ' depending on which quote is preferred. */ + quote: string; + /** True if unquoted keys were used at least once. */ + quote_keys: boolean; + /** True if input has a whitespace token. */ + has_whitespace: boolean; + /** True if input has a comment token. */ + has_comments: boolean; + /** True if input has a newline token. */ + has_newlines: boolean; + /** True if input has at least one trailing comma. */ + has_trailing_comma: boolean; +} + +/** + * Parse json/json5 text and returns a javascript value it corresponds to. + * @param text Text to parse + * @param options Parser options + */ +export function parse(text: string, options?: ParseOptions): any; +/** + * Compatibility syntax (follows JSON specification). + * Converts a JavaScript Object Notation (JSON) string into an object. + * @param text A valid JSON string. + * @param reviver A function that transforms the results. This function is called for each member of the object. + * If a member contains nested objects, the nested objects are transformed before the parent object is. + */ +export function parse(text: string, reviver?: (key: any, value: any) => any): any; + +/** + * Convert javascript value to an appropriate json/json5 text. + * @param value Value to serialize + * @param options Serializer options + */ +export function stringify(value: any, options?: StringifyOptions): string; +/** + * Compatibility syntax (follows JSON specification). + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer A function that transforms the results. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ +export function stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; +/** + * Compatibility syntax (follows JSON specification). + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer An array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ +export function stringify(value: any, replacer?: Array | null, space?: string | number): string; + +/** + * Parse json/json5 text and return an array of tokens it consists of. + * @param text Text to tokenize + * @param options Parser options + */ +export function tokenize(text: string, options?: ParseOptions): Token[]; + +/** + * Parse json/json5 text and try to guess indentation, quoting style, etc. + * @param text Text to analyze + * @param options Parser options + */ +export function analyze(text: string, options?: ParseOptions): JsonStyle; + +/** + * Change json/json5 text, preserving original formatting as much as possible. + * @param text Original text + * @param new_value New value you want to set + * @param options Parser or stringifier options + * + * @example + * // here is your original JSON document: + * var input = '{"foo": "bar", "baz": 123}' + * + * // you need to parse it first: + * var json = jju.parse(input, {mode: 'json'}) + * // json is { foo: 'bar', baz: 123 } + * + * // then you can change it as you like: + * json.foo = 'quux' + * json.hello = 'world' + * + * // then you run an update function to change the original json: + * var output = jju.update(input, json, {mode: 'json'}) + * // output is '{"foo": "quux", "baz": 123, "hello": "world"}' + */ +export function update(text: string, new_value: any, options?: ParseOptions | StringifyOptions): string; diff --git a/types/jju/jju-tests.ts b/types/jju/jju-tests.ts new file mode 100644 index 0000000000..0de4d973b1 --- /dev/null +++ b/types/jju/jju-tests.ts @@ -0,0 +1,4 @@ +import * as jju from 'jju'; + +jju.parse('{}'); // $ExpectType any +jju.stringify({}); // $ExpectType string diff --git a/types/jju/tsconfig.json b/types/jju/tsconfig.json new file mode 100644 index 0000000000..08bb6638c7 --- /dev/null +++ b/types/jju/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jju-tests.ts" + ] +} diff --git a/types/jju/tslint.json b/types/jju/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jju/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 5068c7952765e6d19337c6fedaa58dba6195ff9d Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Wed, 28 Nov 2018 20:29:55 -0800 Subject: [PATCH 179/792] Allow parse and stringify options for update() --- types/jju/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/jju/index.d.ts b/types/jju/index.d.ts index 46fbf2f77b..f8bf96d639 100644 --- a/types/jju/index.d.ts +++ b/types/jju/index.d.ts @@ -192,7 +192,7 @@ export function analyze(text: string, options?: ParseOptions): JsonStyle; * Change json/json5 text, preserving original formatting as much as possible. * @param text Original text * @param new_value New value you want to set - * @param options Parser or stringifier options + * @param options Parser and stringifier options * * @example * // here is your original JSON document: @@ -210,4 +210,4 @@ export function analyze(text: string, options?: ParseOptions): JsonStyle; * var output = jju.update(input, json, {mode: 'json'}) * // output is '{"foo": "quux", "baz": 123, "hello": "world"}' */ -export function update(text: string, new_value: any, options?: ParseOptions | StringifyOptions): string; +export function update(text: string, new_value: any, options?: ParseOptions & StringifyOptions): string; From 12b2403208f432eab01af6d45acd095fdcfb9ea6 Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 29 Nov 2018 13:57:50 +0900 Subject: [PATCH 180/792] Simplify css attribute declaration, add jsdoc --- types/styled-components/index.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/styled-components/index.d.ts b/types/styled-components/index.d.ts index ee64b37772..2f3b6b4ec5 100644 --- a/types/styled-components/index.d.ts +++ b/types/styled-components/index.d.ts @@ -454,6 +454,11 @@ declare module "react" { // nature of this declaration. // If you are writing this inline you already have access to all the attributes anyway, // no need for the extra indirection. - css?: import(".").CSSIntrinsicAttributeType; // tslint:disable-line whitespace + /** + * If present, this React element will be converted by + * `babel-plugin-styled-components` into a styled component + * with the given css as its styles. + */ + css?: CSSIntrinsicAttributeType; } } From f8a55ca2b6d82464c53dccbf01e75971ecdff5c0 Mon Sep 17 00:00:00 2001 From: taoqf Date: Thu, 29 Nov 2018 13:48:15 +0800 Subject: [PATCH 181/792] add definition baidu-app --- types/baidu-app/baidu-app-tests.ts | 2007 ++++++++++++ types/baidu-app/index.d.ts | 4758 ++++++++++++++++++++++++++++ types/baidu-app/tsconfig.json | 24 + types/baidu-app/tslint.json | 7 + 4 files changed, 6796 insertions(+) create mode 100644 types/baidu-app/baidu-app-tests.ts create mode 100644 types/baidu-app/index.d.ts create mode 100644 types/baidu-app/tsconfig.json create mode 100644 types/baidu-app/tslint.json diff --git a/types/baidu-app/baidu-app-tests.ts b/types/baidu-app/baidu-app-tests.ts new file mode 100644 index 0000000000..9987a650ee --- /dev/null +++ b/types/baidu-app/baidu-app-tests.ts @@ -0,0 +1,2007 @@ +(() => { + swan.request({ + url: 'https://smartprogram.baidu.com/xxx', // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„ζŽ₯ε£εœ°ε€ + method: 'GET', + dataType: 'json', + data: { + key: 'value' + }, + header: { + 'content-type': 'application/json' // 默θ€ε€Ό + }, + success(res) { + console.log(res.data); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + + const requestTask = swan.request({ + url: 'test.php', // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„ζŽ₯ε£εœ°ε€ + data: { + x: '', + y: '' + }, + header: { + 'content-type': 'application/json' + }, + success(res) { + console.log(res.data); + } + }); + // ε–ζΆˆθ―·ζ±‚δ»»εŠ‘ + requestTask.abort(); +})(); + +(() => { + swan.chooseImage({ + success(res) { + swan.uploadFile({ + url: 'https://smartprogram.baidu.com/xxx', // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„ζŽ₯ε£εœ°ε€ + filePath: res.tempFilePaths[0], // θ¦δΈŠδΌ ζ–‡δ»Άθ΅„ζΊηš„θ·―εΎ„ + name: 'myfile', + success(res) { + console.log(res.statusCode); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + } + }); +})(); + +(() => { + const uploadTask = swan.uploadFile({ + url: 'https://smartprogram.baidu.com/xxx', // εΌ€ε‘θ€…ζœεŠ‘ε™¨ url + filePath: '', // res.tempFilePaths[0], // θ¦δΈŠδΌ ζ–‡δ»Άθ΅„ζΊηš„θ·―εΎ„ + name: 'myfile', + success(res) { + console.log(res.statusCode); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + + uploadTask.onProgressUpdate(res => { + console.log('δΈŠδΌ θΏ›εΊ¦', res.progress); + console.log('ε·²η»δΈŠδΌ ηš„ζ•°ζι•ΏεΊ¦', res.totalBytesSent); + console.log('ι’„ζœŸιœ€θ¦δΈŠδΌ ηš„ζ•°ζζ€»ι•ΏεΊ¦', res.totalBytesExpectedToSend); + }); + + uploadTask.abort(); // ε–ζΆˆδΈŠδΌ δ»»εŠ‘ +})(); + +(() => { + swan.downloadFile({ + url: 'https://smartprogram.baidu.com/xxx', // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„衄源 + success(res) { + // δΈ‹θ½½ζˆεŠŸ + if (res.statusCode === 200) { + console.log("δΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„" + res.tempFilePath); + } + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + const downloadTask = swan.downloadFile({ + url: 'https://smartprogram.baidu.com/xxx', // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„衄源 + success(res) { + console.log(res.tempFilePath); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + + downloadTask.onProgressUpdate(res => { + console.log('δΈ‹θ½½θΏ›εΊ¦', res.progress); + console.log('ε·²η»δΈ‹θ½½ηš„ζ•°ζι•ΏεΊ¦', res.totalBytesWritten); + console.log('ι’„ζœŸιœ€θ¦δΈ‹θ½½ηš„ζ•°ζζ€»ι•ΏεΊ¦', res.totalBytesExpectedToWrite); + }); + + downloadTask.abort(); // ε–ζΆˆδΈ‹θ½½δ»»εŠ‘ +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com' + }); +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com' + }); + swan.onSocketOpen((res) => { + console.log('WebSocket连ζŽ₯已打开!', res.header); + }); +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com' // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„ζœεŠ‘εœ°ε€ + }); + swan.onSocketError((res) => { + console.log('WebSocket连ζŽ₯打开倱θ΄₯οΌŒθ―·ζ£€ζŸ₯!'); + }); +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com' + }); + swan.onSocketOpen(() => { + swan.sendSocketMessage({ + data: 'baidu' + }); + }); +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com' + }); + swan.onSocketOpen(() => { + swan.sendSocketMessage({ + data: 'baidu' + }); + }); + swan.onSocketMessage((res) => { + console.log('ζ”Άεˆ°ζœεŠ‘ε™¨ε†…εΉοΌš', res.data); + }); +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com', + success(res) { + swan.closeSocket(); + } + }); +})(); + +(() => { + swan.connectSocket({ + url: 'wss://example.baidu.com' + }); + + swan.onSocketClose((res) => { + console.log('WebSocket 已关闭!'); + }); + + swan.onSocketOpen(() => { + swan.closeSocket(); + }); +})(); + +(() => { + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.ocrIdCard({ + image, + success(res) { + console.log(res.words_result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.ocrBankCard({ + image, + success(res) { + console.log(res.result.bank_name); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.ocrDrivingLicense({ + image, + success(res) { + console.log(res.words_result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.ocrVehicleLicense({ + image, + success(res) { + console.log(res.words_result); + } + }); + } + }); +})(); + +(() => { + swan.ai.textReview({ + content: '', + success(res) { + console.log(res.result.spam); // 0 葨瀺ε‘ζ Έι€šθΏ‡ + } + }); +})(); + +(() => { + swan.ai.textToAudio({ + ctp: '1', + lan: 'zh', + tex: 'θΏ™ζ˜―δΈ€ζ΅ζ΅‹θ―•ζ–‡ε­—', + success(res) { + console.log(res.filePath); + } + }); +})(); + +(() => { + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.imageAudit({ + image, + success(res) { + console.log(res.conclusionType); // 1 δΈΊεˆθ§„ + } + }); + } + }); +})(); + +(() => { + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.advancedGeneralIdentify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.objectDetectIdentify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.carClassify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.dishClassify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.logoClassify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.animalClassify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); + swan.chooseImage({ + success(res) { + const image = res.tempFilePaths[0]; + swan.ai.plantClassify({ + image, + success(res) { + console.log(res.result); + } + }); + } + }); +})(); + +(() => { + const voiceRecognizer = swan.ai.getVoiceRecognizer(); + + voiceRecognizer.onStart(() => { + console.log('voice start'); + }); + voiceRecognizer.onRecognize(res => { + console.log('voice recognize', res); + }); + voiceRecognizer.onFinish(res => { + console.log('voice end', res); + }); + voiceRecognizer.onError(err => { + console.log('voice error', err); + }); + + const options = { + mode: 'dnn', + longSpeech: false + }; + + voiceRecognizer.start(options); +})(); + +(() => { + swan.chooseImage({ + count: 1, + sizeType: ['original', 'compressed'], // 可δ»₯ζŒ‡εšζ˜―εŽŸε›ΎθΏ˜ζ˜―εŽ‹ηΌ©ε›ΎοΌŒι»˜θ€δΊŒθ€…ιƒ½ζœ‰ + sourceType: ['album', 'camera'], // 可δ»₯ζŒ‡εšζ₯ζΊζ˜―η›Έε†ŒθΏ˜ζ˜―η›ΈζœΊοΌŒι»˜θ€δΊŒθ€…ιƒ½ζœ‰ + success(res) { + // ζˆεŠŸεˆ™θΏ”ε›žε›Ύη‰‡ηš„ζœ¬εœ°ζ–‡δ»Άθ·―εΎ„εˆ—θ‘¨ tempFilePaths + console.log(res.tempFilePaths); + // ζ–‡δ»Άεˆ—θ‘¨ε―Ήθ±‘ + console.log(res.tempFiles); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + swan.previewImage({ + current: '', // ε½“ε‰ζ˜Ύη€Ίε›Ύη‰‡ηš„httpι“ΎζŽ₯ + urls: [], // ιœ€θ¦ι’„θ§ˆηš„ε›Ύη‰‡httpι“ΎζŽ₯εˆ—θ‘¨ + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + + swan.getImageInfo({ + src: '/xxx/xxx.jpg', + success(res) { + // ζˆεŠŸεˆ™θΏ”ε›žε›Ύη‰‡ι«˜οΌŒε½οΌŒζœ¬εœ°θ·―εΎ„ + console.log(res.width); + console.log(res.height); + console.log(res.path); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + swan.saveImageToPhotosAlbum({ + filePath: '/xxx/xxx.jpg', + success(res) { + console.log(res); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + const recorderManager = swan.getRecorderManager(); + + recorderManager.onStart(() => { + // εΌ€ε§‹ε½•ιŸ³δΊ‹δ»Ά + console.log('recorder start'); + }); + recorderManager.onPause(() => { + // ζš‚εœε½•ιŸ³δΊ‹δ»Ά + console.log('recorder pause'); + }); + recorderManager.onStop((res) => { + // εœζ­’ε½•ιŸ³δΊ‹δ»Ά + console.log('recorder stop', res); + const { tempFilePath } = res; + }); + + const options = { + duration: 10000, + sampleRate: 44100, + numberOfChannels: 1, + encodeBitRate: 96000, + format: 'aac' + }; + + recorderManager.start(options); +})(); + +(() => { + const backgroundAudioManager = swan.getBackgroundAudioManager(); + + backgroundAudioManager.title = 'ζ­€ζ—Άζ­€εˆ»'; + backgroundAudioManager.epname = 'ζ­€ζ—Άζ­€εˆ»'; + backgroundAudioManager.singer = 'θΈε·'; + backgroundAudioManager.coverImgUrl = 'xxx'; + backgroundAudioManager.src = 'xxx'; +})(); + +(() => { + const innerAudioContext = swan.createInnerAudioContext(); + innerAudioContext.src = 'xxx'; + innerAudioContext.autoplay = true; + innerAudioContext.seek({ + position: 10 + }); + innerAudioContext.onPlay((res) => { + console.log('εΌ€ε§‹ζ’­ζ”Ύ'); + }); +})(); + +(() => { + Page({ + data: { + sourceType: ['album', 'camera'], + compressed: false, + maxDuration: 60, + src: '' + }, + + chooseVideo() { + const self = this; + swan.chooseVideo({ + sourceType: this.getData('sourceType'), + compressed: this.getData('compressed'), + maxDuration: this.getData('maxDuration'), + success(res) { + // ζˆεŠŸθΏ”ε›žι€‰εšθ§†ι’‘ηš„δΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„ + self.setData('src', res.tempFilePath); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + } + }); + swan.saveVideoToPhotosAlbum({ + filePath: 'bdfile://xxx', + success(res) { + console.log(res); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + const myVideo = swan.createVideoContext('myVideo'); + myVideo.play(); +})(); + +(() => { + swan.chooseImage({ + count: 1, + success(res) { + const tempFilePaths = res.tempFilePaths; + swan.saveFile({ + tempFilePath: tempFilePaths[0], + success(res) { + const savedFilePath = res.savedFilePath; + } + }); + } + }); + swan.getFileInfo({ + filePath: 'bdfile://somefile', + success(res) { + console.log(res.size); + console.log(res.digest); + } + }); + swan.getSavedFileList({ + success(res) { + const fileList = res.fileList; + } + }); + swan.getSavedFileInfo({ + filePath: 'bdfile://somefile', + success(res) { + console.log(res.size); + console.log(res.createTime); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + swan.getSavedFileList({ + success(res) { + if (res.fileList.length > 0) { + swan.removeSavedFile({ + filePath: res.fileList[0].filePath, + success(res) { + console.log(res.filePath); + } + }); + } + } + }); +})(); + +(() => { + swan.downloadFile({ + url: 'https://smartprogram.baidu.com/xxx.pdf', + success(res) { + const filePath = res.tempFilePath; + swan.openDocument({ + filePath, + success(res) { + console.log('ζ‰“εΌ€ζ–‡ζ‘£ζˆεŠŸ'); + } + }); + } + }); +})(); + +(() => { + swan.setStorage({ + key: 'key', + data: 'value' + }); +})(); + +(() => { + try { + swan.setStorageSync('key', 'value'); + } catch (e) { + } + swan.getStorage({ + key: 'key', + success(res) { + console.log(res.data); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + try { + const result = swan.getStorageSync('key'); + } catch (e) { + } + swan.getStorageInfo({ + success(res) { + console.log(res.keys); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + try { + const result = swan.getStorageInfoSync(); + console.log(result); + } catch (e) { + } +})(); + +(() => { + swan.removeStorage({ + key: 'key', + success(res) { + console.log(res); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + try { + swan.removeStorageSync('key'); + } catch (e) { + } + try { + swan.clearStorageSync(); + } catch (e) { + } +})(); + +(() => { + swan.getLocation({ + type: 'gcj02', + success(res) { + console.log('纬度:' + res.latitude); + console.log('经度:' + res.longitude); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + swan.getLocation({ + type: 'gcj02', + success(res) { + swan.openLocation({ + latitude: res.latitude, + longitude: res.longitude, + scale: 18 + }); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + let mapContext: swan.MapContext; + Page({ + data: { + latitude: '40.042500', + longitude: '116.274040', + }, + onReady() { + mapContext = swan.createMapContext('myMap'); + }, + getCenterLocation() { + mapContext.getCenterLocation({ + success(res) { + console.log("经度" + res.longitude); + console.log("ηΊ¬εΊ¦" + res.latitude); + } + }); + }, + moveToLocation() { + mapContext.moveToLocation(); + }, + translateMarker() { + mapContext.translateMarker({ + markerId: 0, + rotate: 90, + autoRotate: true, + duration: 1000, + destination: { + latitude: 23.10229, + longitude: 113.3345211, + }, + animationEnd() { + console.log('animation end'); + } + }); + }, + includePoints() { + mapContext.includePoints({ + padding: [10], + points: [{ + latitude: 23, + longitude: 113.33, + }, { + latitude: 23, + longitude: 113.3345211, + }] + }); + }, + getRegion() { + mapContext.getRegion({ + success(res) { + console.log("θ₯Ώε—θ§’ηš„η»ηΊ¬εΊ¦" + res.southwest); + console.log("δΈœεŒ—θ§’ηš„η»ηΊ¬εΊ¦" + res.northeast); + } + }); + } + }); +})(); + +(() => { + Page({ + onReady() { + const ctx = this.createCanvasContext('myCanvas'); + ctx.setFillStyle('#ff0000'); + ctx.arc(100, 100, 50, 0, 2 * Math.PI); + ctx.fill(); + ctx.draw(); + } + }); + Page({ + onReady() { + const ctx = this.createCanvasContext('myCanvas'); + } + }); + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setFillStyle('#ff0000'); + ctx.arc(100, 100, 50, 0, 2 * Math.PI); + ctx.fill(); + + ctx.draw(); + + swan.canvasGetImageData({ + canvasId: 'myCanvas', + x: 0, + y: 0, + width: 100, + height: 100, + success(res) { + console.log(res); + } + }); + const data = new Uint8ClampedArray([255, 0, 0, 1]); + swan.canvasPutImageData({ + canvasId: 'myCanvas', + data, + x: 0, + y: 0, + width: 1, + height: 2, + success(res) { + console.log('success'); + } + }); + swan.canvasToTempFilePath({ + x: 100, + y: 200, + width: 50, + height: 50, + destWidth: 100, + destHeight: 100, + canvasId: 'myCanvas', + success(res) { + console.log(res.tempFilePath); + } + }); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setFillStyle('blue'); + ctx.fillRect(30, 30, 150, 75); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setFillStyle('blue'); + ctx.setShadow(10, 50, 50, 'red'); + ctx.fillRect(30, 30, 150, 75); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + // Create linear gradient + const grd = ctx.createLinearGradient(0, 0, 200, 0); + grd.addColorStop(0, 'blue'); + grd.addColorStop(1, 'red'); + + // Fill with gradient + ctx.setFillStyle(grd); + ctx.fillRect(30, 30, 150, 80); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + // Create circular gradient + const grd = ctx.createCircularGradient(75, 50, 50); + grd.addColorStop(0, 'red'); + grd.addColorStop(1, 'blue'); + + // Fill with gradient + ctx.setFillStyle(grd); + ctx.fillRect(30, 30, 150, 80); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + // Create circular gradient + const grd = ctx.createLinearGradient(30, 10, 120, 10); + grd.addColorStop(0, 'red'); + grd.addColorStop(0.16, 'orange'); + grd.addColorStop(0.33, 'yellow'); + grd.addColorStop(0.5, 'green'); + grd.addColorStop(0.66, 'cyan'); + grd.addColorStop(0.83, 'blue'); + grd.addColorStop(1, 'purple'); + + // Fill with gradient + ctx.setFillStyle(grd); + ctx.fillRect(30, 30, 150, 80); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.beginPath(); + ctx.moveTo(30, 10); + ctx.lineTo(200, 10); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineWidth(5); + ctx.moveTo(50, 30); + ctx.lineTo(200, 30); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineWidth(10); + ctx.moveTo(70, 50); + ctx.lineTo(200, 50); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineWidth(15); + ctx.moveTo(90, 70); + ctx.lineTo(200, 70); + ctx.stroke(); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.beginPath(); + ctx.moveTo(30, 10); + ctx.lineTo(200, 10); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineCap('butt'); + ctx.setLineWidth(10); + ctx.moveTo(50, 30); + ctx.lineTo(200, 30); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineCap('round'); + ctx.setLineWidth(10); + ctx.moveTo(70, 50); + ctx.lineTo(200, 50); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineCap('square'); + ctx.setLineWidth(10); + ctx.moveTo(90, 70); + ctx.lineTo(200, 70); + ctx.stroke(); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.beginPath(); + ctx.moveTo(10, 10); + ctx.lineTo(100, 50); + ctx.lineTo(10, 90); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineJoin('bevel'); + ctx.setLineWidth(10); + ctx.moveTo(50, 10); + ctx.lineTo(140, 50); + ctx.lineTo(50, 90); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineJoin('round'); + ctx.setLineWidth(10); + ctx.moveTo(90, 10); + ctx.lineTo(180, 50); + ctx.lineTo(90, 90); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineJoin('miter'); + ctx.setLineWidth(10); + ctx.moveTo(130, 10); + ctx.lineTo(220, 50); + ctx.lineTo(130, 90); + ctx.stroke(); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setLineDash([10, 20], 5); + ctx.beginPath(); + ctx.moveTo(0, 100); + ctx.lineTo(400, 100); + ctx.stroke(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.beginPath(); + ctx.setLineWidth(10); + ctx.setLineJoin('miter'); + ctx.setMiterLimit(1); + ctx.moveTo(10, 10); + ctx.lineTo(100, 50); + ctx.lineTo(10, 90); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineWidth(10); + ctx.setLineJoin('miter'); + ctx.setMiterLimit(2); + ctx.moveTo(50, 10); + ctx.lineTo(140, 50); + ctx.lineTo(50, 90); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineWidth(10); + ctx.setLineJoin('miter'); + ctx.setMiterLimit(3); + ctx.moveTo(90, 10); + ctx.lineTo(180, 50); + ctx.lineTo(90, 90); + ctx.stroke(); + + ctx.beginPath(); + ctx.setLineWidth(10); + ctx.setLineJoin('miter'); + ctx.setMiterLimit(4); + ctx.moveTo(130, 10); + ctx.lineTo(220, 50); + ctx.lineTo(130, 90); + ctx.stroke(); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.rect(30, 30, 150, 75); + ctx.setFillStyle('blue'); + ctx.fill(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setFillStyle('blue'); + ctx.fillRect(30, 30, 150, 75); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setStrokeStyle('blue'); + ctx.strokeRect(30, 30, 150, 75); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setFillStyle('red'); + ctx.fillRect(0, 0, 150, 200); + ctx.setFillStyle('blue'); + ctx.fillRect(150, 0, 150, 200); + ctx.clearRect(30, 30, 150, 75); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.moveTo(100, 100); + ctx.lineTo(10, 100); + ctx.lineTo(10, 10); + ctx.fill(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.moveTo(100, 100); + ctx.lineTo(10, 100); + ctx.lineTo(10, 10); + ctx.stroke(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.rect(10, 10, 100, 30); + ctx.setFillStyle('red'); + ctx.fill(); + ctx.beginPath(); + ctx.rect(10, 40, 100, 30); + ctx.setFillStyle('blue'); + ctx.fillRect(10, 70, 100, 30); + ctx.rect(10, 100, 100, 30); + ctx.setFillStyle('green'); + ctx.fill(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.moveTo(100, 100); + ctx.lineTo(10, 100); + ctx.lineTo(10, 10); + ctx.closePath(); + ctx.stroke(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.moveTo(10, 10); + ctx.lineTo(100, 10); + ctx.moveTo(10, 100); + ctx.lineTo(100, 100); + ctx.stroke(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.moveTo(10, 10); + ctx.rect(10, 10, 100, 50); + ctx.lineTo(110, 60); + ctx.stroke(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.arc(100, 75, 50, 0, 2 * Math.PI); + ctx.setFillStyle('blue'); + ctx.fill(); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.strokeRect(10, 10, 25, 15); + ctx.scale(2, 2); + ctx.strokeRect(10, 10, 25, 15); + ctx.scale(2, 2); + ctx.strokeRect(10, 10, 25, 15); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.strokeRect(100, 10, 150, 100); + ctx.rotate(20 * Math.PI / 180); + ctx.strokeRect(100, 10, 150, 100); + ctx.rotate(20 * Math.PI / 180); + ctx.strokeRect(100, 10, 150, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.strokeRect(10, 10, 150, 100); + ctx.translate(20, 20); + ctx.strokeRect(10, 10, 150, 100); + ctx.translate(20, 20); + ctx.strokeRect(10, 10, 150, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + swan.downloadFile({ + url: 'https://b.bdstatic.com/searchbox/icms/searchbox/img/LOGO300x300.jpg', + success(res) { + ctx.save(); + ctx.beginPath(); + ctx.arc(50, 50, 25, 0, 2 * Math.PI); + ctx.clip(); + ctx.drawImage(res.tempFilePath, 25, 25); + ctx.restore(); + ctx.draw(); + } + }); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.setFontSize(20); + ctx.fillText('20', 20, 20); + ctx.setFontSize(30); + ctx.fillText('30', 40, 40); + ctx.setFontSize(40); + ctx.fillText('40', 60, 60); + ctx.setFontSize(50); + ctx.fillText('50', 90, 90); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.setFontSize(20); + ctx.fillText('Hello', 20, 20); + ctx.fillText('World', 100, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.setStrokeStyle('red'); + ctx.moveTo(150, 20); + ctx.lineTo(150, 170); + ctx.stroke(); + + ctx.setFontSize(15); + ctx.setTextAlign('left'); + ctx.fillText('textAlign=left', 150, 60); + + ctx.setTextAlign('center'); + ctx.fillText('textAlign=center', 150, 80); + + ctx.setTextAlign('right'); + ctx.fillText('textAlign=right', 150, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.setStrokeStyle('red'); + ctx.moveTo(5, 75); + ctx.lineTo(295, 75); + ctx.stroke(); + + ctx.setFontSize(20); + + ctx.setTextBaseline('top'); + ctx.fillText('top', 5, 75); + + ctx.setTextBaseline('middle'); + ctx.fillText('middle', 50, 75); + + ctx.setTextBaseline('bottom'); + ctx.fillText('bottom', 120, 75); + + ctx.setTextBaseline('normal'); + ctx.fillText('normal', 200, 75); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + swan.chooseImage({ + success(res) { + ctx.drawImage(res.tempFilePaths[0], 0, 0, 150, 100); + ctx.draw(); + } + }); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + + ctx.setFillStyle('red'); + ctx.fillRect(10, 10, 150, 100); + ctx.setGlobalAlpha(0.2); + ctx.setFillStyle('blue'); + ctx.fillRect(50, 50, 150, 100); + ctx.setFillStyle('yellow'); + ctx.fillRect(100, 100, 150, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.font = 'italic bold 20px cursive'; + const metrics = ctx.measureText('Hello World'); + console.log(metrics.width); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + const pattern = ctx.createPattern('/path/to/image', 'repeat-x'); + ctx.fillStyle = pattern; + ctx.fillRect(0, 0, 300, 150); + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + // Draw quadratic curve + ctx.beginPath(); + ctx.moveTo(20, 20); + ctx.bezierCurveTo(20, 100, 200, 100, 200, 20); + ctx.setStrokeStyle('black'); + ctx.stroke(); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + // Draw quadratic curve + ctx.beginPath(); + ctx.moveTo(20, 20); + ctx.quadraticCurveTo(20, 100, 200, 20); + ctx.setStrokeStyle('blue'); + ctx.stroke(); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + // save the default fill style + ctx.save(); + ctx.setFillStyle('blue'); + ctx.fillRect(10, 10, 150, 100); + + // restore to the previous saved state + ctx.restore(); + ctx.fillRect(50, 50, 150, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + // save the default fill style + ctx.save(); + ctx.setFillStyle('blue'); + ctx.fillRect(10, 10, 150, 100); + + // restore to the previous saved state + ctx.restore(); + ctx.fillRect(50, 50, 150, 100); + + ctx.draw(); +})(); + +(() => { + const ctx = swan.createCanvasContext('myCanvas'); + ctx.setFillStyle('blue'); + ctx.fillRect(10, 10, 150, 100); + ctx.draw(); + ctx.fillRect(30, 30, 150, 100); + ctx.draw(); +})(); + +(() => { + swan.showToast({ + title: 'ζˆ‘ζ˜―ζ ‡ι’˜', + icon: 'loading', + duration: 1000, + }); + swan.showLoading({ + title: '加载中', + mask: 'true' + }); + + setTimeout(() => { + swan.hideLoading(); + }, 2000); + + swan.showModal({ + title: '提瀺', + content: 'θΏ™ζ˜―δΈ€δΈͺ樑态弹ηͺ—', + cancelColor: '#999999', + confirmColor: '#0099cc', + success(res) { + if (res.confirm) { + console.log('η”¨ζˆ·η‚Ήε‡»δΊ†η‘εš'); + } else if (res.cancel) { + console.log('η”¨ζˆ·η‚Ήε‡»δΊ†ε–ζΆˆ'); + } + } + }); + swan.showActionSheet({ + itemList: ['εŒζ„', 'δΈ€θˆ¬', 'δΈεŒζ„'], + success(res) { + console.log(`η”¨ζˆ·η‚Ήε‡»δΊ†η¬¬${(res.tapIndex + 1)}δΈͺζŒ‰ι’`); + } + }); +})(); + +(() => { + swan.setNavigationBarTitle({ + title: 'ζˆ‘ζ˜―ι‘΅ι’ζ ‡ι’˜' + }); + swan.setNavigationBarColor({ + frontColor: '#ffffff', + backgroundColor: '#ff0000', + animation: { + duration: 500, + timingFunc: 'linear' + } + }); +})(); + +(() => { + swan.setTabBarBadge({ + index: 0, + text: 'ζ–‡ζœ¬' + }); + swan.removeTabBarBadge({ + index: 0 + }); + swan.showTabBarRedDot({ + index: 0 + }); + swan.hideTabBarRedDot({ + index: 0 + }); + swan.setTabBarStyle({ + color: '#FFFFBD', + selectedColor: '#FFFFBD', + backgroundColor: '#FFFFBD', + borderStyle: 'white' + }); + swan.setTabBarItem({ + index: 0, + text: 'ζ–‡ζœ¬', + // 图片路径 + iconPath: '/images/component_normal.png', + // 选中图片路径 + selectedIconPath: '/images/component_selected.png', + }); + swan.showTabBar({ + success(res) { + console.log(res); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); + swan.hideTabBar({ + success(res) { + console.log(res); + }, + fail(err) { + console.log('ι”™θ――η οΌš' + err.errCode); + console.log('ι”™θ――δΏ‘ζ―οΌš' + err.errMsg); + } + }); +})(); + +(() => { + swan.navigateTo({ + // ζ­€θ·―εΎ„δΈΊη›Έε―Ήθ·―εΎ„οΌ›ε¦‚ιœ€ε†™δΈΊη»ε―Ήεœ°ε€οΌŒεˆ™ε―ε†™δΈΊβ€˜/example/xxx?key=valu’。 + url: 'example/xxx?key=value' + }); + swan.redirectTo({ + // ζ­€θ·―εΎ„δΈΊη›Έε―Ήθ·―εΎ„οΌ›ε¦‚ιœ€ε†™δΈΊη»ε―Ήεœ°ε€οΌŒεˆ™ε―ε†™δΈΊβ€˜/example/xxx?key=valu’。 + url: 'example/xxx?key=value' + }); + swan.switchTab({ + url: '/list', + }); + // ζ³¨ζ„οΌšθ°ƒη”¨ navigateTo θ·³θ½¬ζ—ΆοΌŒθ°ƒη”¨ι‘΅ι’δΌšθ’«εŠ ε…₯ε †ζ ˆοΌŒθ€Œ redirectTo ζ–Ήζ³•εˆ™δΈδΌšγ€‚θ§δΈ‹ζ–Ήη€ΊδΎ‹δ»£η  + + // ε½“ε‰ζ˜―ι¦–ι‘΅ + swan.navigateTo({ + url: 'list?key=value' + }); + + // ε½“ε‰ζ˜―εˆ—θ‘¨ι‘΅ + swan.navigateTo({ + url: 'detail?key=value' + }); + + // εœ¨θ―¦ζƒ…ι‘΅ε†… navigateBackοΌŒε°†θΏ”ε›žι¦–ι‘΅ + swan.navigateBack({ + delta: 2 + }); + swan.reLaunch({ + // ζ­€θ·―εΎ„δΈΊη›Έε―Ήθ·―εΎ„οΌ›ε¦‚ιœ€ε†™δΈΊη»ε―Ήεœ°ε€οΌŒεˆ™ε―ε†™δΈΊβ€˜/example/xxx?key=valu’。 + url: 'example/xxx?key=value' + }); +})(); + +(() => { + const animation = swan.createAnimation({ + transformOrigin: "50% 50%", + duration: 1000, + timingFunction: "ease", + delay: 0 + }); + Page({ + data: { + animationData: {} + }, + starttoanimate() { + const animation = swan.createAnimation(); + animation.rotate(90).translateY(10).step(); + animation.rotate(-90).translateY(-10).step(); + this.setData({ + animationData: animation.export() + }); + } + }); +})(); + +(() => { + swan.pageScrollTo({ + scrollTop: 0, + duration: 300 + }); +})(); + +(() => { + Page({ + onPullDownRefresh() { + // do something + } + }); + swan.startPullDownRefresh(); + swan.stopPullDownRefresh(); +})(); + +(() => { + swan.createIntersectionObserver({} as any, { + selectAll: true + }).relativeTo('.container') + .observe('.ball', res => { + console.log(res.intersectionRect); // η›ΈδΊ€εŒΊεŸŸ + console.log(res.intersectionRect.left); // η›ΈδΊ€εŒΊεŸŸηš„ε·¦θΎΉη•Œεζ ‡ + console.log(res.intersectionRect.top); // η›ΈδΊ€εŒΊεŸŸηš„δΈŠθΎΉη•Œεζ ‡ + console.log(res.intersectionRect.width); // η›ΈδΊ€εŒΊεŸŸηš„ε½εΊ¦ + console.log(res.intersectionRect.height); // η›ΈδΊ€εŒΊεŸŸηš„ι«˜εΊ¦ + }); + Page({ + queryMultipleNodes() { + const query = swan.createSelectorQuery(); + query.select('#the-id').boundingClientRect(); + query.selectViewport().scrollOffset(); + query.exec((res) => { + // res[0].top, // #the-idθŠ‚η‚Ήηš„δΈŠθΎΉη•Œεζ ‡ + // res[1].scrollTop // ζ˜Ύη€ΊεŒΊεŸŸηš„η«–η›΄ζ»šεŠ¨δ½η½ + }); + } + }); + Component({ + // queryMultipleNodes() { + // const query = swan.createSelectorQuery().in(this); + // query.select('#the-id').boundingClientRect((res) => { + // // res.top // θΏ™δΈͺη»„δ»Άε†… #the-id θŠ‚η‚Ήηš„δΈŠθΎΉη•Œεζ ‡ + // }).exec(); + // } + }); + Page({ + getRect() { + swan.createSelectorQuery().select('#the-id').boundingClientRect((res) => { + const rect = res as swan.NodesRefRect; + rect.id; // θŠ‚η‚Ήηš„ID + rect.dataset; // θŠ‚η‚Ήηš„dataset + rect.left; // θŠ‚η‚Ήηš„ε·¦θΎΉη•Œεζ ‡ + rect.right; // θŠ‚η‚Ήηš„ε³θΎΉη•Œεζ ‡ + rect.top; // θŠ‚η‚Ήηš„δΈŠθΎΉη•Œεζ ‡ + rect.bottom; // θŠ‚η‚Ήηš„δΈ‹θΎΉη•Œεζ ‡ + rect.width; // θŠ‚η‚Ήηš„ε½εΊ¦ + rect.height; // θŠ‚η‚Ήηš„ι«˜εΊ¦ + }).exec(); + }, + getAllRects() { + swan.createSelectorQuery().selectAll('.a-class').boundingClientRect((rects) => { + (rects as swan.NodesRefRect[]).forEach((rect) => { + rect.id; // θŠ‚η‚Ήηš„ID + rect.dataset; // θŠ‚η‚Ήηš„dataset + rect.left; // θŠ‚η‚Ήηš„ε·¦θΎΉη•Œεζ ‡ + rect.right; // θŠ‚η‚Ήηš„ε³θΎΉη•Œεζ ‡ + rect.top; // θŠ‚η‚Ήηš„δΈŠθΎΉη•Œεζ ‡ + rect.bottom; // θŠ‚η‚Ήηš„δΈ‹θΎΉη•Œεζ ‡ + rect.width; // θŠ‚η‚Ήηš„ε½εΊ¦ + rect.height; // θŠ‚η‚Ήηš„ι«˜εΊ¦ + }); + }).exec(); + } + }); + Page({ + getScrollOffset() { + swan.createSelectorQuery().selectViewport().scrollOffset((res) => { + res.id; // θŠ‚η‚Ήηš„ID + res.dataset; // θŠ‚η‚Ήηš„dataset + res.scrollLeft; // θŠ‚η‚Ήηš„ζ°΄εΉ³ζ»šεŠ¨δ½η½ + res.scrollTop; // θŠ‚η‚Ήηš„η«–η›΄ζ»šεŠ¨δ½η½ + }).exec(); + } + }); + Page({ + getFields() { + swan.createSelectorQuery().select('#the-id').fields({ + dataset: true, + size: true, + scrollOffset: true, + properties: ['scrollX', 'scrollY'], + computedStyle: ['margin', 'backgroundColor'] + }, (res) => { + res.dataset; // θŠ‚η‚Ήηš„dataset + res.width; // θŠ‚η‚Ήηš„ε½εΊ¦ + res.height; // θŠ‚η‚Ήηš„ι«˜εΊ¦ + res.scrollLeft; // θŠ‚η‚Ήηš„ζ°΄εΉ³ζ»šεŠ¨δ½η½ + res.scrollTop; // θŠ‚η‚Ήηš„η«–η›΄ζ»šεŠ¨δ½η½ + res.scrollX; // θŠ‚η‚Ή scroll-x ε±žζ€§ηš„ε½“ε‰ε€Ό + res.scrollY; // θŠ‚η‚Ή scroll-y ε±žζ€§ηš„ε½“ε‰ε€Ό + // ζ­€ε€„θΏ”ε›žζŒ‡εšθ¦θΏ”ε›žηš„ζ ·εΌε + res.margin; + res.backgroundColor; + }).exec(); + } + }); +})(); + +(() => { + swan.getSystemInfo({ + success(res) { + console.log(res.model); + console.log(res.pixelRatio); + console.log(res.windowWidth); + console.log(res.windowHeight); + console.log(res.language); + console.log(res.version); + console.log(res.platform); + } + }); + try { + const res = swan.getSystemInfoSync(); + console.log(res.model); + console.log(res.pixelRatio); + console.log(res.windowWidth); + console.log(res.windowHeight); + console.log(res.language); + console.log(res.version); + console.log(res.platform); + } catch (e) { + // Do something when catch error + } + try { + const res = swan.getEnvInfoSync(); + console.log(res.appKey); + console.log(res.appName); + console.log(res.lastAppURL); + console.log(res.sdkVersion); + console.log(res.scheme); + } catch (e) { + // Do something when catch error + } + swan.canIUse('view.hover-class'); + swan.canIUse('scroll-view.scroll-x'); + swan.canIUse('cover-view'); + swan.canIUse('button.size.default'); + swan.canIUse('button.size.default'); + swan.canIUse('request.object.success.data'); + swan.canIUse('getSavedFileList'); + swan.canIUse('getSavedFileList.object'); + swan.canIUse('getSavedFileList.object.success'); +})(); + +(() => { + swan.onMemoryWarning((res) => { + console.log('onMemoryWarningReceive'); + }); +})(); + +(() => { + swan.getNetworkType({ + success(res) { + console.log(res.networkType); + } + }); + swan.onNetworkStatusChange((res) => { + console.log(res.isConnected); + console.log(res.networkType); + }); +})(); + +(() => { + swan.onAccelerometerChange((res) => { + console.log(res.x); + console.log(res.y); + console.log(res.z); + }); + swan.startAccelerometer({ + interval: 'ui' + }); + swan.stopAccelerometer(); +})(); + +(() => { + swan.onCompassChange((res) => { + console.log(res.direction); + }); + swan.startCompass(); + swan.stopCompass(); +})(); + +(() => { + swan.scanCode({ + success(res) { + console.log(res.result); + console.log(res.scanType); + } + }); +})(); + +(() => { + swan.onUserCaptureScreen(() => { + console.log('η”¨ζˆ·ζˆͺ屏了'); + }); +})(); + +(() => { + swan.makePhoneCall({ + phoneNumber: '000000' // δ»…δΈΊη€ΊδΎ‹οΌŒεΉΆιžηœŸεžηš„甡话号码 + }); +})(); + +(() => { + swan.setClipboardData({ + data: 'baidu', + success(res) { + swan.getClipboardData({ + success(res) { + console.log(res.data); // baidu + } + }); + } + }); + swan.getClipboardData({ + success(res) { + console.log(res.data); + } + }); +})(); + +(() => { + swan.getExtConfig({ + success(res) { + console.log(res.extConfig); + } + }); + const data = swan.getExtConfigSync(); + console.log(data.extConfig); +})(); + +(() => { + swan.login({ + success(res) { + swan.request({ + url: 'https://xxx/xxx', // εΌ€ε‘θ€…ζœεŠ‘ε™¨εœ°ε€ + data: { + code: res.code + } + }); + }, + fail(err) { + console.log('login fail', err); + } + }); + swan.checkSession({ + success(res) { + console.log('η™»ε½•ζ€ζœ‰ζ•ˆ'); + swan.getUserInfo({ + success(res) { + console.log('η”¨ζˆ·ε', res.userInfo.nickName); + swan.request({ + url: "https://xxx/decrypt_user_data", // εΌ€ε‘θ€…ζœεŠ‘ε™¨εœ°ε€οΌŒε―Ή data θΏ›θ‘Œθ§£ε―† + data: { + data: res.data, + iv: res.iv + } + }); + } + }); + }, + fail(err) { + console.log('η™»ε½•ζ€ζ— ζ•ˆ'); + swan.login({ + success(res) { + swan.request({ + url: 'https://xxx/xxx', // εΌ€ε‘θ€…ζœεŠ‘ε™¨εœ°ε€οΌŒη”¨ code 捒取 session_key + data: { + code: res.code + } + }); + }, + fail(err) { + console.log('登录倱θ΄₯', err); + } + }); + } + }); + + try { + const result = swan.isLoginSync(); + console.log('isLoginSync', result); + } catch (e) { + console.log('error', e); + } +})(); + +(() => { + swan.authorize({ + scope: 'scope.userLocation', + success(res) { + // η”¨ζˆ·ε·²η»εŒζ„ζ™Ίθƒ½ε°η¨‹εΊδ½Ώη”¨εšδ½εŠŸθƒ½ + swan.getLocation(); + } + }); +})(); + +(() => { + swan.getSwanId({ + success(res) { + console.log(res.data.swanid); + } + }); + swan.getUserInfo({ + success(res) { + console.log('η”¨ζˆ·ε', res.userInfo.nickName); + } + }); +})(); + +(() => { + swan.openSetting({ + success(res) { + console.log(res.authSetting['scope.userInfo']); + console.log(res.authSetting['scope.userLocation']); + } + }); + swan.getSetting({ + success(res) { + console.log(res.authSetting['scope.userInfo']); + console.log(res.authSetting['scope.userLocation']); + } + }); +})(); + +(() => { + Page({ + onShareAppMessage() { + return { + title: '智能小程序瀺例', + content: 'δΈ–η•ŒεΎˆε€ζ‚οΌŒη™ΎεΊ¦ζ›΄ζ‡‚δ½ ', + path: '/pages/openShare/openShare?key=value' + }; + } + }); + swan.openShare({ + title: '智能小程序瀺例', + content: 'δΈ–η•ŒεΎˆε€ζ‚οΌŒη™ΎεΊ¦ζ›΄ζ‡‚δ½ ', + path: '/pages/openShare/openShare?key=value' + }); +})(); + +(() => { + swan.chooseAddress({ + success(res) { + console.log(res.userName); + console.log(res.postalCode); + console.log(res.provinceName); + console.log(res.cityName); + console.log(res.countyName); + console.log(res.detailInfo); + console.log(res.telNumber); + } + }); +})(); + +(() => { + swan.requestPolymerPayment({ + orderInfo: { + dealId: "470193086", + appKey: "MMMabc", + totalAmount: "1", + tpOrderId: "3028903626", + dealTitle: "智能小程序Demoζ”―δ»˜ζ΅‹θ―•", + signFieldsRange: 1, + rsaSign: '', + bizInfo: '' + }, + success(res) { + swan.showToast({ + title: 'ζ”―δ»˜ζˆεŠŸ', + icon: 'success' + }); + }, + fail(err) { + swan.showToast({ + title: JSON.stringify(err) + }); + console.log('pay fail', err); + } + }); +})(); + +(() => { + swan.chooseInvoiceTitle({ + success(res) { + console.log(res.type); + console.log(res.title); + console.log(res.taxNumber); + console.log(res.companyAddress); + console.log(res.telephone); + console.log(res.bankName); + console.log(res.bankAccount); + } + }); +})(); + +(() => { + swan.navigateToSmartProgram({ + appKey: '4fecoAqgCIUtzIyA4FAPgoyrc4oUc25c', // θ¦ζ‰“εΌ€ηš„ε°η¨‹εΊ App Key + path: '', // ζ‰“εΌ€ηš„ι‘΅ι’θ·―εΎ„οΌŒε¦‚ζžœδΈΊη©Ίεˆ™ζ‰“εΌ€ι¦–ι‘΅ + extraData: { + foo: 'baidu' + }, + success(res) { + // ζ‰“εΌ€ζˆεŠŸ + } + }); + swan.navigateBackSmartProgram({ + extraData: { + foo: 'baidu' + }, + success(res) { + // θΏ”ε›žζˆεŠŸ + } + }); +})(); + +(() => { + if (swan.setMetaDescription) { + swan.setMetaDescription({ + content: '当前小程序鑡青描述俑息', + success(res) { + console.log('θΎη½ζˆεŠŸ'); + }, + fail(res) { + console.log('θΎη½ε€±θ΄₯'); + }, + complete(res) { + console.log('θΎη½ε€±θ΄₯'); + } + }); + } + if (swan.setMetaKeywords) { + swan.setMetaKeywords({ + content: '小程序, ε…³ι”ε­—', + success(res) { + console.log('θΎη½ζˆεŠŸ'); + }, + fail(res) { + console.log('θΎη½ε€±θ΄₯'); + }, + complete(res) { + console.log('θΎη½ε€±θ΄₯'); + } + }); + } + if (swan.setDocumentTitle) { + swan.setDocumentTitle({ + title: 'ζˆ‘ζ˜―ι‘΅ι’ζ ‡ι’˜' + }); + } +})(); + +(() => { + swan.loadSubPackage({ + root: 'subpackage', + success(res) { + console.log('δΈ‹θ½½ζˆεŠŸ', res); + }, + fail(err) { + console.log('δΈ‹θ½½ε€±θ΄₯', err); + } + }); +})(); + +(() => { + const updateManager = swan.getUpdateManager(); + + updateManager.onCheckForUpdate((res) => { + // 请求εŒζ–°η‰ˆζœ¬δΏ‘ζ―ηš„ε›žθ°ƒ + console.log(res.hasUpdate); + }); + + updateManager.onUpdateReady((res) => { + swan.showModal({ + title: '更新提瀺', + content: 'ζ–°η‰ˆζœ¬ε·²η»ε‡†ε€‡ε₯½οΌŒζ˜―ε¦ι‡ε―εΊ”η”¨οΌŸ', + success(res) { + if (res.confirm) { + // ζ–°ηš„η‰ˆζœ¬ε·²η»δΈ‹θ½½ε₯½οΌŒθ°ƒη”¨ applyUpdate εΊ”η”¨ζ–°η‰ˆζœ¬εΉΆι‡ε― + updateManager.applyUpdate(); + } + } + }); + }); + + updateManager.onUpdateFailed((res) => { + // ζ–°ηš„η‰ˆζœ¬δΈ‹θ½½ε€±θ΄₯ + }); +})(); + +(() => { + // 打开调试 + swan.setEnableDebug({ + enableDebug: true + }); + + // ε…³ι—­θ°ƒθ―• + swan.setEnableDebug({ + enableDebug: false + }); +})(); + +(() => { + swan.reportAnalytics('purchase', { + price: 120, + color: 'red' + }); +})(); diff --git a/types/baidu-app/index.d.ts b/types/baidu-app/index.d.ts new file mode 100644 index 0000000000..244e9dd473 --- /dev/null +++ b/types/baidu-app/index.d.ts @@ -0,0 +1,4758 @@ +// Type definitions for swan-app 2.2 +// Project: https://smartprogram.baidu.com/docs/develop/tutorial/codedir/ +// Definitions by: taoqf +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.8 + +declare namespace swan { + // #region εŸΊζœ¬ε‚ζ•° + interface DataResponse { + /** ε›žθ°ƒε‡½ζ•°θΏ”ε›žηš„ε†…εΉ */ + data: string | ArrayBuffer; + statusCode: number; + header: any; + result: string; + } + interface ErrMsgResponse { + /** 成功:okοΌŒι”™θ――οΌšθ―¦η»†δΏ‘ζ― */ + errMsg: "ok" | string; + } + interface TempFileResponse { + /** ζ–‡δ»Άηš„δΈ΄ζ—Άθ·―εΎ„ */ + tempFilePath: string; + /** εΌ€ε‘θ€…ζœεŠ‘ε™¨θΏ”ε›žηš„ HTTP ηŠΆζ€η  */ + statusCode: number; + } + interface BaseOptions { + /** ζŽ₯ε£θ°ƒη”¨ζˆεŠŸηš„ε›žθ°ƒε‡½ζ•° */ + success?(res: R): void; + /** ζŽ₯口调用倱θ΄₯ηš„ε›žθ°ƒε‡½ζ•° */ + fail?(res: E): void; + /** ζŽ₯ε£θ°ƒη”¨η»“ζŸηš„ε›žθ°ƒε‡½ζ•°οΌˆθ°ƒη”¨ζˆεŠŸγ€ε€±θ΄₯ιƒ½δΌšζ‰§θ‘ŒοΌ‰ */ + complete?(res: any): void; + } + interface ErrCodeResponse { + errCode: number; + } + // #endregion + // #region η½‘η»œAPIεˆ—θ‘¨ + // 发衷请求 + interface RequestHeader { + [key: string]: string; + } + interface RequestOptions extends BaseOptions { + /** εΌ€ε‘θ€…ζœεŠ‘ε™¨ζŽ₯ε£εœ°ε€ */ + url: string; + /** θ―·ζ±‚ηš„ε‚ζ•° */ + data?: string | object; + /** θΎη½θ―·ζ±‚ηš„ header , header 中不能θΎη½ Referer */ + header?: RequestHeader; + /** 默θ€δΈΊ GETοΌŒζœ‰ζ•ˆε€ΌοΌšOPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT */ + method?: + | "GET" + | "OPTIONS" + | "GET" + | "HEAD" + | "POST" + | "PUT" + | "DELETE"; + /** ε¦‚ζžœθΎδΈΊjsonοΌŒδΌšε°θ―•ε―ΉθΏ”ε›žηš„ζ•°ζεšδΈ€ζ¬‘ JSON.parse 默θ€ε€ΌδΈΊjson */ + dataType?: string; + /** + * θΎη½ε“εΊ”ηš„ζ•°ζη±»εž‹γ€‚εˆζ³•ε€ΌοΌštext、arraybuffer 默θ€ε€ΌδΈΊtext + * @version 1.7.0 + */ + responseType?: string; + /** ζ”Άεˆ°εΌ€ε‘θ€…ζœεŠ‘ζˆεŠŸθΏ”ε›žηš„ε›žθ°ƒε‡½ζ•°οΌŒres = {data: 'εΌ€ε‘θ€…ζœεŠ‘ε™¨θΏ”ε›žηš„ε†…εΉ'} */ + success?(res: DataResponse): void; + fail?(err: { errCode: number; errMsg: string; }): void; + } + /** + * swan.requestε‘θ΅·ηš„ζ˜―https请求。一δΈͺεΎδΏ‘ε°η¨‹εΊοΌŒεŒζ—Άεͺθƒ½ζœ‰5δΈͺη½‘η»œθ―·ζ±‚θΏžζŽ₯。 + */ + function request(options: RequestOptions): RequestTask; + + /** + * θΏ”ε›žδΈ€δΈͺ requestTask ε―Ήθ±‘οΌŒι€šθΏ‡ requestTaskοΌŒε―δΈ­ζ–­θ―·ζ±‚δ»»εŠ‘γ€‚ + */ + interface RequestTask { + abort(): void; + } + + interface UploadTask { + /** + * η›‘ε¬δΈŠδΌ θΏ›εΊ¦ε˜εŒ– + * @version 1.4.0 + */ + onProgressUpdate( + callback?: ( + res: { + /** δΈŠδΌ θΏ›εΊ¦η™Ύεˆ†ζ―” */ + progress: number; + /** ε·²η»δΈŠδΌ ηš„ζ•°ζι•ΏεΊ¦οΌŒε•位 Bytes */ + totalBytesSent: number; + /** ι’„ζœŸιœ€θ¦δΈŠδΌ ηš„ζ•°ζζ€»ι•ΏεΊ¦οΌŒε•位 Bytes */ + totalBytesExpectedToSend: number; + } + ) => void + ): void; + /** + * δΈ­ζ–­δΈ‹θ½½δ»»εŠ‘ + * @version 1.4.0 + */ + abort(): void; + } + // δΈŠδΌ δΈ‹θ½½ + interface UploadFileOptions extends BaseOptions { + /** εΌ€ε‘θ€…ζœεŠ‘ε™¨ url */ + url: string; + /** θ¦δΈŠδΌ ζ–‡δ»Άθ΅„ζΊηš„θ·―εΎ„ */ + filePath: string; + /** ζ–‡δ»Άε―ΉεΊ”ηš„ key , εΌ€ε‘θ€…εœ¨ζœεŠ‘ε™¨η«―ι€šθΏ‡θΏ™δΈͺ key 可δ»₯θŽ·ε–εˆ°ζ–‡δ»ΆδΊŒθΏ›εˆΆε†…εΉ */ + name: string; + /** HTTP 请求 Header , header 中不能θΎη½ Referer */ + header?: RequestHeader; + /** HTTP θ―·ζ±‚δΈ­ε…Άδ»–ι’ε€–ηš„ form data */ + formData?: any; + } + interface UploadFileResponse { + data: string; // εΌ€ε‘θ€…ζœεŠ‘ε™¨θΏ”ε›žηš„ζ•°ζ + statusCode: number; // εΌ€ε‘θ€…ζœεŠ‘ε™¨θΏ”ε›žηš„ HTTP ηŠΆζ€η  + } + /** + * ε°†ζœ¬εœ°θ΅„ζΊδΈŠδΌ εˆ°εΌ€ε‘θ€…ζœεŠ‘ε™¨γ€‚ + * ε¦‚ι‘΅ι’ι€šθΏ‡ swan.chooseImage η­‰ζŽ₯ε£θŽ·ε–εˆ°δΈ€δΈͺζœ¬εœ°θ΅„ζΊηš„δΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„εŽοΌŒ + * ε―ι€šθΏ‡ζ­€ζŽ₯ε£ε°†ζœ¬εœ°θ΅„ζΊδΈŠδΌ εˆ°ζŒ‡εšζœεŠ‘器。 + * ε’ζˆ·η«―ε‘θ΅·δΈ€δΈͺ HTTPS POST θ―·ζ±‚οΌŒ + * ε…ΆδΈ­ Content-Type δΈΊ multipart/form-data 。 + */ + function uploadFile(options: UploadFileOptions): UploadTask; + interface DownloadTask { + /** + * η›‘ε¬δΈ‹θ½½θΏ›εΊ¦ε˜εŒ– + * @version 1.4.0 + */ + onProgressUpdate( + callback?: ( + res: { + /** δΈ‹θ½½θΏ›εΊ¦η™Ύεˆ†ζ―” */ + progress: number; + /** ε·²η»δΈ‹θ½½ηš„ζ•°ζι•ΏεΊ¦οΌŒε•位 Bytes */ + totalBytesWritten: number; + /** ι’„ζœŸιœ€θ¦δΈ‹θ½½ηš„ζ•°ζζ€»ι•ΏεΊ¦οΌŒε•位 Bytes */ + totalBytesExpectedToWrite: number; + } + ) => void + ): void; + /** + * δΈ­ζ–­δΈ‹θ½½δ»»εŠ‘ + * @version 1.4.0 + */ + abort(): void; + } + interface DownloadFileOptions extends BaseOptions { + /** δΈ‹θ½½θ΅„ζΊηš„ url */ + url: string; + /** HTTP 请求 Header */ + header?: RequestHeader; + /** δΈ‹θ½½ζˆεŠŸεŽδ»₯ tempFilePath ηš„ε½’εΌδΌ η»™ι‘΅ι’οΌŒres = {tempFilePath: 'ζ–‡δ»Άηš„δΈ΄ζ—Άθ·―εΎ„'} */ + success?(res: TempFileResponse): void; + } + /** + * δΈ‹θ½½ζ–‡δ»Άθ΅„ζΊεˆ°ζœ¬εœ°γ€‚ε’ζˆ·η«―η›΄ζŽ₯发衷一δΈͺ HTTP GET θ―·ζ±‚οΌŒ + * ζŠŠδΈ‹θ½½εˆ°ηš„θ΅„ζΊζ Ήζ type θΏ›θ‘Œε€„η†οΌŒεΉΆθΏ”ε›žζ–‡δ»Άηš„ζœ¬εœ°δΈ΄ζ—Άθ·―εΎ„γ€‚ + */ + function downloadFile(options: DownloadFileOptions): DownloadTask; + // WebSocket + interface ConnectSocketOptions extends BaseOptions { + /** εΌ€ε‘θ€…ζœεŠ‘ε™¨ζŽ₯ε£εœ°ε€οΌŒεΏ…ι‘»ζ˜― HTTPS 协θοΌŒδΈ”εŸŸεεΏ…ι‘»ζ˜―εŽε°ι…η½ηš„εˆζ³•εŸŸε */ + url: string; + /** HTTP Header , header 中不能θΎη½ Referer */ + header?: RequestHeader; + /** 默θ€ζ˜―GETοΌŒζœ‰ζ•ˆε€ΌδΈΊοΌš OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT */ + method?: string; + /** + * 子协θζ•°η»„ + * @version 1.4.0 + */ + protocols?: string[]; + } + /** + * εˆ›ε»ΊδΈ€δΈͺ WebSocket 连ζŽ₯οΌ› + * δΈ€δΈͺεΎδΏ‘ε°η¨‹εΊεŒζ—Άεͺθƒ½ζœ‰δΈ€δΈͺ WebSocket 连ζŽ₯, + * ε¦‚ζžœε½“ε‰ε·²ε­˜εœ¨δΈ€δΈͺ WebSocket 连ζŽ₯, + * 会θ‡ͺεŠ¨ε…³ι—­θ―₯连ζŽ₯οΌŒεΉΆι‡ζ–°εˆ›ε»ΊδΈ€δΈͺ WebSocket 连ζŽ₯。 + */ + function connectSocket(options: ConnectSocketOptions): void; + /** 监听WebSocket连ζŽ₯打开事仢。 */ + function onSocketOpen(callback: (res: any) => void): void; + /** 监听WebSocket错误。 */ + function onSocketError(callback: (error: any) => void): void; + interface SendSocketMessageOptions extends BaseOptions { + /** ιœ€θ¦ε‘ι€ηš„ε†…εΉ */ + data: string | ArrayBuffer; + } + /** + * ι€šθΏ‡ WebSocket 连ζŽ₯发送数ζοΌŒιœ€θ¦ε…ˆ swan.connectSocket, + * 幢在 swan.onSocketOpen ε›žθ°ƒδΉ‹εŽζ‰θƒ½ε‘ι€γ€‚ + */ + function sendSocketMessage(options: SendSocketMessageOptions): void; + /** + * 监听WebSocketζŽ₯ε—εˆ°ζœεŠ‘ε™¨ηš„ζΆˆζ―δΊ‹δ»Άγ€‚ + */ + function onSocketMessage(callback: (res: DataResponse) => void): void; + /** + * ε…³ι—­WebSocket连ζŽ₯。 + */ + interface CloseSocketOptions extends BaseOptions { + code?: number; // δΈ€δΈͺζ•°ε­—ε€Όθ‘¨η€Ίε…³ι—­θΏžζŽ₯ηš„ηŠΆζ€ε·οΌŒθ‘¨η€ΊθΏžζŽ₯θ’«ε…³ι—­ηš„εŽŸε› γ€‚ε¦‚ζžœθΏ™δΈͺε‚ζ•°ζ²‘ζœ‰θ’«ζŒ‡εšοΌŒι»˜θ€ηš„ε–ε€Όζ˜―1000 (葨瀺正常连ζŽ₯ε…³ι—­οΌ‰ 1.4.0 + reason?: string; // δΈ€δΈͺε―θ―»ηš„ε­—η¬¦δΈ²οΌŒθ‘¨η€ΊθΏžζŽ₯θ’«ε…³ι—­ηš„εŽŸε› γ€‚θΏ™δΈͺε­—η¬¦δΈ²εΏ…ι‘»ζ˜―δΈι•ΏδΊŽ123ε­—θŠ‚ηš„UTF-8 ζ–‡ζœ¬οΌˆδΈζ˜―ε­—η¬¦οΌ‰ + } + + /** + * ε…³ι—­WebSocket连ζŽ₯。 + */ + function closeSocket(options?: CloseSocketOptions): void; + /** 监听WebSocket关闭。 */ + function onSocketClose(callback: (res: any) => void): void; + /** + * 在ζŽ₯ε…₯AIδΉ‹ε‰ιœ€θ¦δ½Ώη”¨η‘η†ε‘˜ζƒι™ζ“δ½œθ―¦η»†ζƒ…ε†΅ε˜η½‘ + * https://smartprogram.baidu.com/docs/develop/api/ai/ + */ + // #region AI + namespace ai { + /** + * η”¨ζˆ·ε‘ζœεŠ‘θ―·ζ±‚θ―†εˆ«θΊ«δ»½θ―οΌŒθΊ«δ»½θ―θ―†εˆ«εŒ…ζ‹¬ζ­£ι’ε’ŒθƒŒι’γ€‚ + */ + interface ocrIdCardOptions extends BaseOptions { + image: string; // ε›Ύη‰‡θ΅„ζΊεœ°ε€ + detect_direction?: boolean; // ζ˜―ε¦ζ£€ζ΅‹ε›Ύεƒζ—‹θ½¬οΌŒε―ζ£€ιͺŒε›Ύεƒηš„ι€‰θ£…ζ–Ήε‘ε’Œζ—‹θ½¬θ§’εΊ¦γ€‚trueοΌšζ£€ζ΅‹ζ—‹θ½¬θ§’εΊ¦εΉΆηŸ«ζ­£θ―†εˆ«γ€‚ι’ˆε―Ήζ‘†ζ”Ύζƒ…ε†΅δΈε―ζŽ§εˆΆηš„ζƒ…ε†΅ε»Ίθζœ¬ε‚ζ•°η½δΈΊtrue; false: δΈζ£€ζ΅‹ζ—‹θ½¬θ§’εΊ¦οΌŒι»˜θ€δΈζ£€ζ΅‹γ€‚ + id_card_side?: string; // frontοΌšθΊ«δ»½θ―ε«η…§η‰‡ηš„δΈ€ι’οΌ›backοΌšθΊ«δ»½θ―εΈ¦ε›½εΎ½ηš„δΈ€ι’γ€‚ + detect_risk?: boolean; // ζ˜―ε¦εΌ€ε―θΊ«δ»½θ―ι£Žι™©η±»εž‹(身份证倍印仢、临既身份证、身份证翻拍、δΏζ”ΉθΏ‡ηš„身份证)εŠŸθƒ½οΌŒι»˜θ€δΈεΌ€ε―,即:false。可选值:true-开启;false-不开启。 + success?(res: ocrIdCardResponse): void; + } + /** + * θ―†εˆ«ι“Άθ‘Œε‘εΉΆθΏ”ε›žε‘ε·γ€ε‘ε‘θ‘Œε’Œε‘η‰‡η±»εž‹γ€‚ + */ + interface ocrBankCardOptions extends BaseOptions { + image: string; // ε›Ύη‰‡θ΅„ζΊεœ°ε€ + success?(res: ocrBankCardResponse): void; + } + /** + * ε―ΉζœΊεŠ¨θ½¦ι©Ύι©Άθ―ζ‰€ζœ‰ε…³ι”ε­—ζ΅θΏ›θ‘Œθ―†εˆ«γ€‚ + */ + interface ocrDrivingLicenseOptions extends BaseOptions { + image: string; // ε›Ύη‰‡θ΅„ζΊεœ°ε€ + detect_direction?: boolean; // ζ˜―ε¦ζ£€ζ΅‹ε›Ύεƒζ—‹θ½¬οΌŒε―ζ£€ιͺŒε›Ύεƒηš„ι€‰θ£…ζ–Ήε‘ε’Œζ—‹θ½¬θ§’εΊ¦γ€‚trueοΌšζ£€ζ΅‹ζ—‹θ½¬θ§’εΊ¦εΉΆηŸ«ζ­£θ―†εˆ«γ€‚ι’ˆε―Ήζ‘†ζ”Ύζƒ…ε†΅δΈε―ζŽ§εˆΆηš„ζƒ…ε†΅ε»Ίθζœ¬ε‚ζ•°η½δΈΊtrue;false:δΈζ£€ζ΅‹ζ—‹θ½¬θ§’εΊ¦οΌŒι»˜θ€δΈζ£€ζ΅‹γ€‚ + unified_valid_period?: boolean; // true: ε½’δΈ€εŒ–ζ ΌεΌθΎ“ε‡Ί;false ζˆ–ζ— ζ­€ε‚ζ•°ζŒ‰ιžε½’δΈ€εŒ–ζ ΌεΌθΎ“ε‡Ίγ€‚ + success?(res: ocrDrivingLicenseResponse): void; + } + /** + * ε―ΉζœΊεŠ¨θ½¦θ‘Œι©Άθ―ζ­£ζœ¬ζ‰€ζœ‰ε…³ι”ε­—ζ΅θΏ›θ‘Œθ―†εˆ« + */ + interface ocrVehicleLicenseOptions extends BaseOptions { + image: string; // ε›Ύη‰‡θ΅„ζΊεœ°ε€ + detect_direction?: boolean; // ζ˜―ε¦ζ£€ζ΅‹ε›Ύεƒζ—‹θ½¬οΌŒε―ζ£€ιͺŒε›Ύεƒηš„ι€‰θ£…ζ–Ήε‘ε’Œζ—‹θ½¬θ§’εΊ¦γ€‚trueοΌšζ£€ζ΅‹ζ—‹θ½¬θ§’εΊ¦εΉΆηŸ«ζ­£θ―†εˆ«γ€‚ι’ˆε―Ήζ‘†ζ”Ύζƒ…ε†΅δΈε―ζŽ§εˆΆηš„ζƒ…ε†΅ε»Ίθζœ¬ε‚ζ•°η½δΈΊtrue; false:δΈζ£€ζ΅‹ζ—‹θ½¬θ§’εΊ¦οΌŒι»˜θ€δΈζ£€ζ΅‹γ€‚ + accuracy?: string; // normal δ½Ώη”¨εΏ«ι€ŸζœεŠ‘οΌŒ1200msε·¦ε³ζ—Άε»ΆοΌ›ηΌΊηœζˆ–ε…Άεƒε€Όδ½Ώη”¨ι«˜η²ΎεΊ¦ζœεŠ‘,1600ms左右既廢。 + success?(res: ocrVehicleLicenseResponse): void; + } + interface ocrIdCardResponse { + direction: number; // ε›Ύεƒζ–Ήε‘οΌŒε½“ detect_direction=true ζ—Άε­˜εœ¨γ€‚-1: ζœͺεšδΉ‰οΌŒ0: ζ­£ε‘οΌŒ1: ι€†ζ—Άι’ˆ90度,2: ι€†ζ—Άι’ˆ180度,3: ι€†ζ—Άι’ˆ270度。 + image_status: string; // normal-θ―†εˆ«ζ­£εΈΈοΌ›reversed_side-身份证正反青钠倒;non_idcard-δΈŠδΌ ηš„ε›Ύη‰‡δΈ­δΈεŒ…ε«θΊ«δ»½θ―οΌ›blurred-θΊ«δ»½θ―ζ¨‘η³ŠοΌ›other_type_card-ε…Άδ»–η±»εž‹θ―η…§οΌ›over_exposure-身份证关ι”ε­—ζ΅εε…‰ζˆ–过曝;unknown-ζœͺηŸ₯ηŠΆζ€γ€‚ + risk_type: string; // θΎ“ε…₯参数 detect_risk = true ζ—ΆοΌŒεˆ™θΏ”ε›žθ―₯ε­—ζ΅θ―†εˆ«θΊ«δ»½θ―η±»εž‹: normal-正常身份证;copy-倍印仢;temporary-临既身份证;screen-翻拍;unknown-ε…Άδ»–ζœͺηŸ₯情冡。 + edit_tool: string; // ε¦‚ζžœε‚ζ•° detect_risk = true ζ—ΆοΌŒεˆ™θΏ”ε›žζ­€ε­—ζ΅γ€‚ε¦‚ζžœζ£€ζ΅‹θΊ«δ»½θ―θ’«ηΌ–θΎ‘θΏ‡οΌŒθ―₯ε­—ζ΅ζŒ‡εšηΌ–θΎ‘θ½―δ»Άεη§°οΌŒε¦‚:Adobe Photoshop CC 2014 (Macintosh),ε¦‚ζžœζ²‘ζœ‰θ’«ηΌ–θΎ‘θΏ‡εˆ™θΏ”ε›žε€Όζ— ζ­€ε‚ζ•°γ€‚ + log_id: string; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + words_result_num: number; // θ―†εˆ«η»“ζžœζ•°οΌŒθ‘¨η€Ίwords_resultηš„ε…ƒη΄ δΈͺ数。 + words_result: { // εšδ½ε’Œθ―†εˆ«η»“ζžœ + [key: string]: { + location: { // 位η½ζ•°η»„οΌˆεζ ‡0η‚ΉδΈΊε·¦δΈŠθ§’οΌ‰ + left: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ε·¦δΈŠι‘Άη‚Ήηš„ζ°΄εΉ³εζ ‡γ€‚ + top: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ε·¦δΈŠι‘Άη‚Ήηš„εž‚η›΄εζ ‡γ€‚ + width: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ηš„ε½εΊ¦γ€‚ + height: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ηš„ι«˜γ€‚ + } + words: string; // θ―†εˆ«η»“ζžœε­—η¬¦δΈ² + } + }; + } + interface ocrBankCardResponse { + log_id: string; // θ―·ζ±‚ζ ‡θ―†η οΌŒιšζœΊζ•°οΌŒε”―δΈ€γ€‚ + result: { // θΏ”ε›žη»“ζžœ + bank_card_number: string; // ι“Άθ‘Œε‘ε‘ε· + bank_name: string; // ι“Άθ‘ŒεοΌŒδΈθƒ½θ―†εˆ«ζ—ΆδΈΊη©Ί 。 + bank_card_type: string; // ι“Άθ‘Œε‘η±»εž‹οΌŒ0: δΈθƒ½θ―†εˆ«; 1: ε€Ÿθ°ε‘; 2: 俑用卑 。 + }; + } + interface ocrDrivingLicenseResponse { + log_id: string; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + words_result_num: number; // θ―†εˆ«η»“ζžœζ•°οΌŒθ‘¨η€Ί words_result ηš„ε…ƒη΄ δΈͺ数。 + words_result: { + [key: string]: { words: string }; + }; + } + interface ocrVehicleLicenseResponse { + log_id: string; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + words_result_num: number; // θ―†εˆ«η»“ζžœζ•°οΌŒθ‘¨η€Ί words_result ηš„ε…ƒη΄ δΈͺ数。 + words_result: { + [key: string]: { words: string }; + }; + } + /** + * η”¨ζˆ·ε‘ζœεŠ‘θ―·ζ±‚θ―†εˆ«θΊ«δ»½θ―οΌŒθΊ«δ»½θ―θ―†εˆ«εŒ…ζ‹¬ζ­£ι’ε’ŒθƒŒι’γ€‚ + */ + function ocrIdCard(options: ocrIdCardOptions): void; + /** + * θ―†εˆ«ι“Άθ‘Œε‘εΉΆθΏ”ε›žε‘ε·γ€ε‘ε‘θ‘Œε’Œε‘η‰‡η±»εž‹γ€‚ + */ + function ocrBankCard(options: ocrBankCardOptions): void; + /** + * ε―ΉζœΊεŠ¨θ½¦ι©Ύι©Άθ―ζ‰€ζœ‰ε…³ι”ε­—ζ΅θΏ›θ‘Œθ―†εˆ«γ€‚ + */ + function ocrDrivingLicense(options: ocrDrivingLicenseOptions): void; + /** + * ε―ΉζœΊεŠ¨θ½¦θ‘Œι©Άθ―ζ­£ζœ¬ζ‰€ζœ‰ε…³ι”ε­—ζ΅θΏ›θ‘Œθ―†εˆ« + */ + function ocrVehicleLicense(options: ocrVehicleLicenseOptions): void; + /** + * θΏη”¨δΈšη•Œι’†ε…ˆηš„ζ·±εΊ¦ε­¦δΉ ζŠ€ζœ―οΌŒεˆ€ζ–­δΈ€ζ΅ζ–‡ζœ¬ε†…εΉζ˜―ε¦η¬¦εˆη½‘η»œε‘ζ–‡θ§„θŒƒοΌŒεžηް + * θ‡ͺεŠ¨εŒ–γ€ζ™Ίθƒ½εŒ–ηš„ζ–‡ζœ¬ε‘核。 + */ + interface textReviewOptions extends BaseOptions { + content: string; // εΎ…ε‘ζ Έζ–‡ζœ¬οΌŒUTF-8οΌŒδΈε―δΈΊη©ΊοΌŒδΈθΆ…θΏ‡20000ε­—θŠ‚γ€‚ + success?(res: textReviewResponse): void; + } + interface textReviewResponse { + log_id: string; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result: { // ε‘ζ Έη»“ζžœθ―¦ζƒ… + spam: number; // θ―·ζ±‚δΈ­ζ˜―ε¦εŒ…ε«θΏη¦οΌŒ0葨瀺非违禁,1葨瀺违禁,2葨瀺建θδΊΊε·₯ε€ε‘ γ€‚ + reject: any[]; // ε‘ζ Έζœͺι€šθΏ‡ηš„η±»εˆ«εˆ—θ‘¨δΈŽθ―¦ζƒ… + review: any[]; // εΎ…δΊΊε·₯倍ε‘ηš„η±»εˆ«εˆ—θ‘¨δΈŽθ―¦ζƒ… + pass: Array<{ // ε‘ζ Έι€šθΏ‡ηš„η±»εˆ«εˆ—θ‘¨δΈŽθ―¦ζƒ… + label: number; // θ―·ζ±‚δΈ­ηš„θΏη¦η±»εž‹ + score: number; // θΏη¦ζ£€ζ΅‹εˆ†οΌŒθŒƒε›΄ 0~1οΌŒζ•°ε€Όδ»Žδ½Žεˆ°ι«˜δ»£θ‘¨ι£Žι™©η¨‹εΊ¦ηš„ι«˜δ½Ž 。 + hit: string[]; // θΏη¦η±»εž‹ε―ΉεΊ”ε‘½δΈ­ηš„θΏη¦θ―ι›†εˆοΌŒε―θƒ½δΈΊη©Ί 。 + }>; + }; + /** + * 违禁labelsη±»εž‹θ―΄ζ˜Ž: + * ε€Ό 说明 + * 1 暴恐违禁 + * 2 ζ–‡ζœ¬θ‰²ζƒ… + * 3 ζ”Ώζ²»ζ•ζ„Ÿ + * 4 ζΆζ„ζŽ¨εΉΏ + * 5 δ½ŽδΏ—θΎ±ιͺ‚ + */ + } + /** + * θΏη”¨δΈšη•Œι’†ε…ˆηš„ζ·±εΊ¦ε­¦δΉ ζŠ€ζœ―οΌŒεˆ€ζ–­δΈ€ζ΅ζ–‡ζœ¬ε†…εΉζ˜―ε¦η¬¦εˆη½‘η»œε‘ζ–‡θ§„θŒƒοΌŒεžηް + * θ‡ͺεŠ¨εŒ–γ€ζ™Ίθƒ½εŒ–ηš„ζ–‡ζœ¬ε‘核。 + */ + function textReview(options: textReviewOptions): void; + /** + * ε°†ζ–‡ζœ¬θ½¬ζ’δΈΊε―δ»₯ζ’­ζ”Ύηš„mp3文仢。 + */ + interface textToAudioOptions extends BaseOptions { + tex: string; // εˆζˆηš„ζ–‡ζœ¬οΌŒδ½Ώη”¨UTF-8ηΌ–η οΌŒε°δΊŽ512δΈͺδΈ­ζ–‡ε­—ζˆ–θ€…θ‹±ζ–‡ζ•°ε­—οΌˆζ–‡ζœ¬εœ¨η™ΎεΊ¦ζœεŠ‘ε™¨ε†…θ½¬ζ’δΈΊGBKεŽοΌŒι•ΏεΊ¦εΏ…ι‘»ε°δΊŽ1024ε­—θŠ‚οΌ‰γ€‚ + ctp?: string | number; // ε’ζˆ·η«―η±»εž‹ι€‰ζ‹©οΌŒWeb端呫写固εšε€Ό1。 + lan?: string; // ε›Ίεšε€Όzh。语言选择,η›ε‰εͺζœ‰δΈ­θ‹±ζ–‡ζ··εˆζ¨‘εΌοΌŒε‘«ε†™ε›Ίεšε€Όzh。 + spd?: string; // θ―­ι€ŸοΌŒε–ε€Ό0-9,默θ€δΈΊ5δΈ­θ―­ι€Ÿγ€‚ + pit?: string; // ιŸ³θ°ƒοΌŒε–ε€Ό0-9,默θ€δΈΊ5中语调。 + vol?: string; // ιŸ³ι‡οΌŒε–ε€Ό0-9,默θ€δΈΊ5δΈ­ιŸ³ι‡γ€‚ + per?: string; // ε‘ιŸ³δΊΊι€‰ζ‹©, 0δΈΊζ™ι€šε₯³ε£°οΌŒ1δΈΊζ™ι€šη”·η”ŸοΌŒ3δΈΊζƒ…ζ„Ÿεˆζˆ-度逍ι₯,4δΈΊζƒ…ζ„Ÿεˆζˆ-度丫丫,默θ€δΈΊζ™ι€šε₯³ε£°γ€‚ + success?(res: textToAudioResponse): void; + } + interface textToAudioResponse { + filePath: string; + } + /** + * ε°†ζ–‡ζœ¬θ½¬ζ’δΈΊε―δ»₯ζ’­ζ”Ύηš„mp3文仢。 + */ + function textToAudio(options: textToAudioOptions): void; + /** + * θ‡ͺεšδΉ‰ε›Ύεƒε‘核。 + */ + interface imageAuditOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + imgUrl?: string; // 网图URLεœ°ε€οΌŒδ»₯η½‘ε›Ύε½’εΌθ―·ζ±‚οΌŒε›Ύη‰‡Urlιœ€θ¦εšUrlEncodeοΌŒδΈθƒ½δΈŽimageεΉΆε­˜γ€‚ + success?(res: imageAuditResponse): void; + } + interface imageAuditResponse { + log_id: string; // 请求唯一id + conclusion: string; // ε‘ζ Έη»“ζžœζθΏ°οΌŒζˆεŠŸζ‰θΏ”ε›žοΌŒε€±θ΄₯δΈθΏ”ε›žγ€‚ + conclusionType: number; // ε‘ζ Έη»“ζžœζ ‡θ―†οΌŒζˆεŠŸζ‰θΏ”ε›žοΌŒε€±θ΄₯δΈθΏ”ε›žγ€‚ + data: imageAuditdata[]; + // ε‘ζ Έι‘Ήθ―¦η»†δΏ‘ζ―οΌŒε“εΊ”ζˆεŠŸεΉΆδΈ”conclusionδΈΊη–‘δΌΌζˆ–δΈεˆθ§„ζ—Άζ‰θΏ”ε›žοΌŒε“εΊ”ε€±θ΄₯ζˆ–conclusionδΈΊεˆθ§„ζ˜―δΈθΏ”ε›žγ€‚ + } + interface imageAuditdata { + type: number; + msg: number; + probability: number; + stars: imageAuditdata[]; + words: number; + } + /** + * θ‡ͺεšδΉ‰ε›Ύεƒε‘核。 + */ + function imageAudit(options: imageAuditOptions): void; + /** + * ι€šη”¨η‰©δ½“εŠεœΊζ™―θ―†εˆ«οΌŒε³ε―ΉδΊŽθΎ“ε…₯ηš„δΈ€εΌ ε›Ύη‰‡οΌˆε―ζ­£εΈΈθ§£η οΌŒδΈ”ι•Ώε½ζ―”适εœοΌ‰οΌŒθΎ“ε‡Ίε›Ύη‰‡δΈ­ηš„ε€šδΈͺη‰©δ½“εŠεœΊζ™―ζ ‡η­Ύγ€‚ + */ + interface GeneralIdentifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + success?(res: GeneralIdentifyResponse): void; + } + interface GeneralIdentifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result_num: number; // θΏ”ε›žη»“ζžœζ•°η›οΌŒεŠresultζ•°η»„δΈ­ηš„ε…ƒη΄ δΈͺ数。 + result: Array<{ // ζ ‡η­Ύη»“ζžœζ•°η»„ + keyword: string; // ε›Ύη‰‡δΈ­ηš„η‰©δ½“ζˆ–εœΊζ™―εη§° + score: number; // η½δΏ‘度,0-1 + root: string; // θ―†εˆ«η»“ζžœηš„δΈŠε±‚ζ ‡η­ΎοΌŒζœ‰ιƒ¨εˆ†ι’±εΈγ€εŠ¨ζΌ«γ€ηƒŸι…’η­‰tagζ— δΈŠε±‚ζ ‡η­Ύγ€‚ + }>; + } + /** + * ι€šη”¨η‰©δ½“εŠεœΊζ™―θ―†εˆ«οΌŒε³ε―ΉδΊŽθΎ“ε…₯ηš„δΈ€εΌ ε›Ύη‰‡οΌˆε―ζ­£εΈΈθ§£η οΌŒδΈ”ι•Ώε½ζ―”适εœοΌ‰οΌŒθΎ“ε‡Ίε›Ύη‰‡δΈ­ηš„ε€šδΈͺη‰©δ½“εŠεœΊζ™―ζ ‡η­Ύγ€‚ + */ + function advancedGeneralIdentify(options: GeneralIdentifyOptions): void; + /** + * η”¨ζˆ·ε‘ζœεŠ‘θ―·ζ±‚ζ£€ζ΅‹ε›ΎεƒδΈ­ηš„δΈ»δ½“δ½η½γ€‚ + */ + interface DetectIdentifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + with_face?: number; // ε¦‚ζžœζ£€ζ΅‹δΈ»δ½“ζ˜―δΊΊοΌŒδΈ»δ½“εŒΊεŸŸζ˜―ε¦εΈ¦δΈŠδΊΊθ„Έιƒ¨εˆ†οΌŒ0-δΈεΈ¦δΊΊθ„ΈεŒΊεŸŸοΌŒε…Άδ»–-εΈ¦δΊΊθ„ΈεŒΊεŸŸοΌŒθ£ε‰ͺη±»ιœ€ζ±‚ζŽ¨θεΈ¦δΊΊθ„ΈοΌŒζ£€η΄’/θ―†εˆ«η±»ιœ€ζ±‚ζŽ¨θδΈεΈ¦δΊΊθ„Έγ€‚ι»˜θ€ε–1οΌŒεΈ¦δΊΊθ„Έγ€‚ + success?(res: DetectIdentifyResponse): void; + } + interface DetectIdentifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result: { // 裁ε‰ͺη»“ζžœ + left: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ε·¦δΈŠι‘Άη‚Ήηš„ζ°΄εΉ³εζ ‡γ€‚ + top: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ε·¦δΈŠι‘Άη‚Ήηš„εž‚η›΄εζ ‡γ€‚ + width: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ηš„ε½εΊ¦γ€‚ + height: number; // 葨瀺εšδ½δ½η½ηš„ι•Ώζ–Ήε½’ηš„ι«˜εΊ¦γ€‚ + }; + } + /** + * η”¨ζˆ·ε‘ζœεŠ‘θ―·ζ±‚ζ£€ζ΅‹ε›ΎεƒδΈ­ηš„δΈ»δ½“δ½η½γ€‚ + */ + function objectDetectIdentify(options: DetectIdentifyOptions): void; + /** + * η”¨δΊŽζ£€ζ΅‹δΈ€εΌ θ½¦θΎ†ε›Ύη‰‡ηš„ε…·δ½“θ½¦εž‹οΌŒε³ε―ΉδΊŽθΎ“ε…₯ηš„δΈ€εΌ ε›Ύη‰‡οΌˆε―ζ­£εΈΈθ§£η οΌŒδΈ”ι•Ώ + * ε½ζ―”适εœοΌ‰οΌŒθΎ“ε‡Ίε›Ύη‰‡ηš„θ½¦θΎ†ε“η‰ŒεŠεž‹ε·γ€ι’œθ‰²εŠεΉ΄δ»½γ€δ½η½δΏ‘息。 + */ + interface carClassifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + color_result?: string; // ι’œθ‰² + top_num?: number; // θΏ”ε›žη»“ζžœtop n,默θ€5。 + success?(res: carClassifyResponse): void; + } + interface carClassifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result: Array<{ + name: string; // θ½¦εž‹εη§°οΌŒη€ΊδΎ‹οΌšει©¬x6 + score: number; // η½δΏ‘εΊ¦οΌŒη€ΊδΎ‹οΌš0.5321 + year: string; // εΉ΄δ»½ + }>; + location_result: { // θ½¦εœ¨ε›Ύη‰‡δΈ­ηš„δ½η½δΏ‘息 + left: number; // ε·¦θ΅·εƒη΄ δ½η½ + top: number; // δΈŠθ΅·εƒη΄ δ½η½ + width: number; // εƒη΄ ε½ + height: number; // εƒη΄ ι«˜ + }; + } + /** + * η”¨δΊŽζ£€ζ΅‹δΈ€εΌ θ½¦θΎ†ε›Ύη‰‡ηš„ε…·δ½“θ½¦εž‹οΌŒε³ε―ΉδΊŽθΎ“ε…₯ηš„δΈ€εΌ ε›Ύη‰‡οΌˆε―ζ­£εΈΈθ§£η οΌŒδΈ”ι•Ώ + * ε½ζ―”适εœοΌ‰οΌŒθΎ“ε‡Ίε›Ύη‰‡ηš„θ½¦θΎ†ε“η‰ŒεŠεž‹ε·γ€ι’œθ‰²εŠεΉ΄δ»½γ€δ½η½δΏ‘息。 + */ + function carClassify(options: carClassifyOptions): void; + /** + * η”¨δΊŽθœε“θ―†εˆ«οΌŒε³ε―ΉδΊŽθΎ“ε…₯ηš„δΈ€εΌ ε›Ύη‰‡οΌˆε―ζ­£εΈΈθ§£η οΌŒδΈ”ι•Ώε½ζ―”适εœοΌ‰οΌŒθΎ“ε‡Ίε›Ύ + * η‰‡ηš„θœε“εη§°γ€ε‘θ·―ι‡ŒδΏ‘ζ―γ€η½δΏ‘度。 + */ + interface dishClassifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + filter_threshold?: number; // 默θ€0.95,可δ»₯ι€šθΏ‡θ―₯ε‚ζ•°θ°ƒθŠ‚θ―†εˆ«ζ•ˆζžœοΌŒι™δ½Žιžθœθ―†εˆ«ηŽ‡. + top_num?: number; // θΏ”ε›žη»“ζžœtop n,默θ€5。 + success?(res: dishClassifyResponse): void; + } + interface dishClassifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result_num: number; // θΏ”ε›žη»“ζžœζ•°η›οΌŒεŠresultζ•°η»„δΈ­ηš„ε…ƒη΄ δΈͺ数。 + result: Array<{ // θœε“θ―†εˆ«η»“ζžœζ•°η»„ + name: string; // θœεοΌŒη€ΊδΎ‹οΌšι±Όι¦™θ‚‰δΈγ€‚ + calorie: number; // ε‘θ·―ι‡ŒοΌŒζ―100gηš„ε‘θ·―ι‡Œε«ι‡γ€‚ + probability: number; // θ―†εˆ«η»“ζžœδΈ­ζ―δΈ€θ‘Œηš„η½δΏ‘εΊ¦ε€ΌοΌŒ0-1。 + }>; + } + /** + * η”¨δΊŽθœε“θ―†εˆ«οΌŒε³ε―ΉδΊŽθΎ“ε…₯ηš„δΈ€εΌ ε›Ύη‰‡οΌˆε―ζ­£εΈΈθ§£η οΌŒδΈ”ι•Ώε½ζ―”适εœοΌ‰οΌŒθΎ“ε‡Ίε›Ύ + * η‰‡ηš„θœε“εη§°γ€ε‘θ·―ι‡ŒδΏ‘ζ―γ€η½δΏ‘度。 + */ + function dishClassify(options: dishClassifyOptions): void; + /** + * η”¨δΊŽζ£€ζ΅‹ε’Œθ―†εˆ«ε›Ύη‰‡δΈ­ηš„ε“η‰Œ LOGO 俑息 + */ + interface logoClassifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + custom_lib?: boolean; // 是否εͺζ£€η΄’η”¨ζˆ·ε­εΊ“οΌŒtrueεˆ™εͺζ£€η΄’η”¨ζˆ·ε­εΊ“οΌŒfalse(默θ€)δΈΊζ£€η΄’εΊ•εΊ“+η”¨ζˆ·ε­εΊ“γ€‚ + success?(res: logoClassifyResponse): void; + } + interface logoClassifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result_num: number; // θ―†εˆ«η»“ζžœζ•°οΌŒζ ‡θ―†θΏ”ε›žη»“ζžœζ•°η›γ€‚ + result: Array<{ // θœε“θ―†εˆ«η»“ζžœζ•°η»„ + type: number; // type=0 δΈΊ1εƒη§ι«˜δΌ˜ε•†ζ ‡θ―†εˆ«η»“ζžœοΌ›type=1 δΈΊ2δΈ‡η±»logoεΊ“ηš„η»“ζžœοΌ›ε…ΆεƒtypeδΈΊθ‡ͺεšδΉ‰logoεΊ“η»“ζžœγ€‚ + name: number; // θ―†εˆ«ηš„ε“η‰Œεη§° + probability: number; // εˆ†η±»η»“ζžœη½δΏ‘度(0–1.0οΌ‰ + location: { + left: number; // ε·¦θ΅·εƒη΄ δ½η½ + top: number; // δΈŠθ΅·εƒη΄ δ½η½ + width: number; // εƒη΄ ε½ + height: number; // εƒη΄ ι«˜ + }; // 位η½δΏ‘ζ―οΌˆε·¦θ΅·εƒη΄ δ½η½γ€δΈŠθ΅·εƒη΄ δ½η½γ€εƒη΄ ε½γ€εƒη΄ ι«˜οΌ‰ + }>; + } + /** + * η”¨δΊŽζ£€ζ΅‹ε’Œθ―†εˆ«ε›Ύη‰‡δΈ­ηš„ε“η‰Œ LOGO 俑息 + */ + function logoClassify(options: logoClassifyOptions): void; + /** + * η”¨δΊŽζ£€ζ΅‹ε’Œθ―†εˆ«ε›Ύη‰‡δΈ­ηš„εŠ¨η‰©δΏ‘ζ― + */ + interface animalClassifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + top_num?: number; // θΏ”ε›žι’„ζ΅‹εΎ—εˆ†topη»“ζžœζ•°οΌŒι»˜θ€δΈΊ6 + success?(res: animalClassifyResponse): void; + } + interface animalClassifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result_num: number; // θ―†εˆ«η»“ζžœζ•°οΌŒζ ‡θ―†θΏ”ε›žη»“ζžœζ•°η›γ€‚ + result: Array<{ // θœε“θ―†εˆ«η»“ζžœζ•°η»„ + name: number; // εŠ¨η‰©εη§°οΌŒη€ΊδΎ‹οΌšθ’™ε€ι©¬γ€‚ + score: number; // η½δΏ‘εΊ¦οΌŒη€ΊδΎ‹οΌš0.5321。 + }>; + } + /** + * η”¨δΊŽζ£€ζ΅‹ε’Œθ―†εˆ«ε›Ύη‰‡δΈ­ηš„εŠ¨η‰©δΏ‘ζ― + */ + function animalClassify(options: animalClassifyOptions): void; + /** + * η”¨δΊŽζ£€ζ΅‹ε’Œθ―†εˆ«ε›Ύη‰‡δΈ­ηš„ζ€η‰©δΏ‘ζ― + */ + interface plantClassifyOptions extends BaseOptions { + image: string; // ε›Ύεƒθ΅„ζΊεœ°ε€ + success?(res: plantClassifyResponse): void; + } + interface plantClassifyResponse { + log_id: number; // ε”―δΈ€ηš„log idοΌŒη”¨δΊŽι—ι’˜εšδ½γ€‚ + result: Array<{ // θœε“θ―†εˆ«η»“ζžœζ•°η»„ + name: number; // ζ€η‰©εη§°οΌŒη€ΊδΎ‹οΌšε‰ε¨ƒθŽ²γ€‚ + score: number; // η½δΏ‘εΊ¦οΌŒη€ΊδΎ‹οΌš0.5321。 + }>; + } + /** + * η”¨δΊŽζ£€ζ΅‹ε’Œθ―†εˆ«ε›Ύη‰‡δΈ­ηš„ζ€η‰©δΏ‘ζ― + */ + function plantClassify(options: plantClassifyOptions): void; + + /** + * θŽ·ε–ε…¨ε±€ε”―δΈ€ηš„θ―­ιŸ³θ―†εˆ«ε™¨voiceRecognizer。 + */ + interface VoiceRecognizerStart { + mode?: string; // ε¬ιŸ³ζ¨‘εΌοΌŒζœ‰ζ•ˆε€Όdnn/touch + longSpeech?: boolean; // ζ˜―ε¦εΌ€ε―ι•Ώθ―­ιŸ³ + context?: string; // θ―­ιŸ³θ―†εˆ«ζ‰€η”¨ηš„εœΊζ™―ε€ΌοΌŒζœ‰ζ•ˆε€Όθ§δΈ‹θ‘¨ζ Όγ€‚ + } + interface VoiceRecognizeResponse { + result: string; // ε°η¨‹εΊθ―­ιŸ³θ―†εˆ«θΏ‡η¨‹δΈ­ηš„θΏ”ε›žε†…εΉ + } + interface VoiceErrorResponse { + result: string; // ε°η¨‹εΊθ―­ιŸ³θ―†εˆ«θΏ‡η¨‹δΈ­ηš„θΏ”ε›žε†…εΉ + } + interface VoiceRecognizerTask { + start(options: VoiceRecognizerStart): void; // εΌ€ε§‹; + stop(): void; // 停歒; + cancel(): void; // ε–ζΆˆ; + onStart(callback: () => void): void; // εΌ•ζ“Žε‡†ε€‡ε°±η»ͺ,可δ»₯开始说话; + onRecognize(callback: (res: VoiceRecognizeResponse) => void): void; // ;ζœ‰θ―†εˆ«η»“ζžœθΏ”ε›ž + onFinish(callback: (res: DataResponse) => void): void; // θ―†εˆ«εŒζˆ; + onError(callback: (res: VoiceErrorResponse) => void): void; // θ―†εˆ«ι‡εˆ°ι”™;θ―― + } + /** + * θŽ·ε–ε…¨ε±€ε”―δΈ€ηš„θ―­ιŸ³θ―†εˆ«ε™¨voiceRecognizer。 + */ + function getVoiceRecognizer(): VoiceRecognizerTask; + } + // #endregion + + // #endregion + // #region εͺ’体APIεˆ—θ‘¨ + // εͺ’体-----图片 + type ImageSizeType = "original" | "compressed"; + type ImageSourceType = "album" | "camera"; + type VideoSourceType = "album" | "camera"; + type CameraDevice = "front" | "back"; + interface TempFile { + /** ζœ¬εœ°ζ–‡δ»Άθ·―εΎ„ */ + path: string; + /** ζœ¬εœ°ζ–‡δ»Άε€§ε°οΌŒε•δ½οΌšB */ + size: number; + } + interface TempFilesData { + /** ζ–‡δ»Άηš„δΈ΄ζ—Άθ·―εΎ„ */ + tempFilePaths: string; + /** + * ε›Ύη‰‡ηš„ζœ¬εœ°ζ–‡δ»Άεˆ—θ‘¨οΌŒζ―δΈ€ι‘Ήζ˜―δΈ€δΈͺ File 对豑 + * @version 1.2.0 + */ + tempFiles: TempFile[]; + } + interface ChooseImageOptions extends BaseOptions { + /** ζœ€ε€šε―δ»₯ι€‰ζ‹©ηš„ε›Ύη‰‡εΌ ζ•°οΌŒι»˜θ€9 */ + count?: number; + /** original εŽŸε›ΎοΌŒcompressed εŽ‹ηΌ©ε›ΎοΌŒι»˜θ€δΊŒθ€…ιƒ½ζœ‰ */ + sizeType?: ImageSizeType[]; + /** album δ»Žη›Έε†Œι€‰ε›ΎοΌŒcamera δ½Ώη”¨η›ΈζœΊοΌŒι»˜θ€δΊŒθ€…ιƒ½ζœ‰ */ + sourceType?: ImageSourceType[]; + /** ζˆεŠŸεˆ™θΏ”ε›žε›Ύη‰‡ηš„ζœ¬εœ°ζ–‡δ»Άθ·―εΎ„εˆ—θ‘¨ tempFilePaths */ + success(res: TempFilesData): void; + } + /** + * δ»Žζœ¬εœ°η›Έε†Œι€‰ζ‹©ε›Ύη‰‡ζˆ–δ½Ώη”¨η›ΈζœΊζ‹η…§γ€‚ + */ + function chooseImage(options: ChooseImageOptions): void; + interface PreviewImageOptions extends BaseOptions { + /** ε½“ε‰ζ˜Ύη€Ίε›Ύη‰‡ηš„ι“ΎζŽ₯οΌŒδΈε‘«εˆ™ι»˜θ€δΈΊ urls ηš„η¬¬δΈ€εΌ  */ + current?: string; + /** ιœ€θ¦ι’„θ§ˆηš„ε›Ύη‰‡ι“ΎζŽ₯εˆ—θ‘¨ */ + urls: string[]; + } + /** + * ι’„θ§ˆε›Ύη‰‡γ€‚ + */ + function previewImage(options: PreviewImageOptions): void; + interface GetImageInfoOptions extends BaseOptions { + /** + * ε›Ύη‰‡ηš„θ·―εΎ„οΌŒε―δ»₯ζ˜―η›Έε―Ήθ·―εΎ„οΌŒδΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„οΌŒε­˜ε‚¨ζ–‡δ»Άθ·―εΎ„οΌŒη½‘η»œε›Ύη‰‡θ·―εΎ„ + */ + src: string; + } + /** + * θŽ·ε–ε›Ύη‰‡δΏ‘ζ― + */ + function getImageInfo(options: GetImageInfoOptions): void; + interface SaveImageToPhotosAlbumOptions extends BaseOptions { + /** + * ε›Ύη‰‡ηš„θ·―εΎ„οΌŒε―δ»₯ζ˜―η›Έε―Ήθ·―εΎ„οΌŒδΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„οΌŒε­˜ε‚¨ζ–‡δ»Άθ·―εΎ„οΌŒη½‘η»œε›Ύη‰‡θ·―εΎ„ + */ + filePath: string; + success(res: { errMsg: string }): void; + } + /** + * δΏε­˜ε›Ύη‰‡εˆ°η³»η»Ÿη›Έε†Œγ€‚ + * ιœ€θ¦η”¨ζˆ·ζŽˆζƒ scope.writePhotosAlbum + * @version 1.2.0 + */ + function saveImageToPhotosAlbum(options: SaveImageToPhotosAlbumOptions): void; + // εͺ’体-----ε½•ιŸ³ + interface StartRecordAudioOptions extends BaseOptions { + /** ε½•ιŸ³ζˆεŠŸεŽθ°ƒη”¨οΌŒθΏ”ε›žε½•ιŸ³ζ–‡δ»Άηš„δΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„οΌŒres = {tempFilePath: 'ε½•ιŸ³ζ–‡δ»Άηš„δΈ΄ζ—Άθ·―εΎ„'} */ + success?(res: TempFileResponse): void; + } + /** + * εΌ€ε§‹ε½•ιŸ³γ€‚ε½“δΈ»εŠ¨θ°ƒη”¨swan.stopRecord, + * ζˆ–θ€…ε½•ιŸ³θΆ…θΏ‡1εˆ†ι’Ÿζ—Άθ‡ͺεŠ¨η»“ζŸε½•ιŸ³οΌŒθΏ”ε›žε½•ιŸ³ζ–‡δ»Άηš„δΈ΄ζ—Άζ–‡δ»Άθ·―εΎ„γ€‚ + * ζ³¨οΌšζ–‡δ»Άηš„δΈ΄ζ—Άθ·―εΎ„οΌŒεœ¨ε°η¨‹εΊζœ¬ζ¬‘ε―εŠ¨ζœŸι—΄ε―δ»₯ζ­£εΈΈδ½Ώη”¨οΌŒ + * ε¦‚ιœ€ζŒδΉ…δΏε­˜οΌŒιœ€εœ¨δΈ»εŠ¨θ°ƒη”¨swan.saveFileοΌŒεœ¨ε°η¨‹εΊδΈ‹ζ¬‘ε―εŠ¨ζ—Άζ‰θƒ½θΏι—εΎ—εˆ°γ€‚ + * @deprecated 1.6.0 + */ + function startRecord(options: StartRecordAudioOptions): void; + + interface StopRecordAudioOptions extends BaseOptions { + success?(res: TempFileResponse): void; + } + /** + * δΈ»εŠ¨θ°ƒη”¨εœζ­’ε½•ιŸ³γ€‚ + */ + function stopRecord(options?: StopRecordAudioOptions): void; + type EncodeBitRate = + | 8000 + | 11025 + | 12000 + | 16000 + | 22050 + | 24000 + | 32000 + | 44100 + | 48000; + interface RecorderManagerStartOptions { + /** + * ζŒ‡εšε½•ιŸ³ηš„ζ—Άι•ΏοΌŒε•δ½ ms + * ε¦‚ζžœδΌ ε…₯δΊ†εˆζ³•ηš„ duration + * εœ¨εˆ°θΎΎζŒ‡εšηš„ duration 后会θ‡ͺεŠ¨εœζ­’ε½•ιŸ³οΌŒζœ€ε€§ε€Ό 600000(10 εˆ†ι’ŸοΌ‰,默θ€ε€Ό 60000(1 εˆ†ι’ŸοΌ‰ + */ + duration?: number; + /** + * ι‡‡ζ ·ηŽ‡οΌŒζœ‰ζ•ˆε€Ό 8000/16000/44100 + */ + sampleRate?: number; + /** + * 否 ε½•ιŸ³ι€šι“ζ•°οΌŒζœ‰ζ•ˆε€Ό 1/2 + */ + numberOfChannels?: number; + /** + * ηΌ–η η ηŽ‡ + * ι‡‡ζ ·ηŽ‡ε’Œη ηŽ‡ζœ‰δΈ€εšθ¦ζ±‚οΌŒε…·δ½“ζœ‰ζ•ˆε€Όε¦‚δΈ‹οΌš + * ι‡‡ζ ·ηŽ‡ ηΌ–η η ηŽ‡ + * + 8000 16000 ~ 48000 + * + 11025 16000 ~ 48000 + * + 12000 24000 ~ 64000 + * + 16000 24000 ~ 96000 + * + 22050 32000 ~ 128000 + * + 24000 32000 ~ 128000 + * + 32000 48000 ~ 192000 + * + 44100 64000 ~ 320000 + * + 48000 64000 ~ 320000 + */ + encodeBitRate: number; + /** ιŸ³ι’‘ζ ΌεΌοΌŒζœ‰ζ•ˆε€Ό aac/mp3 */ + format: string; + } + interface OnRecorderManagerStopOptions { + tempFilePath: string; + } + interface OnFrameRecordedOptions { + /** ε½•ιŸ³εˆ†η‰‡η»“ζžœζ•°ζ */ + frameBuffer: ArrayBuffer; + /** ε½“ε‰εΈ§ζ˜―ε¦ζ­£εΈΈε½•ιŸ³η»“ζŸε‰ηš„ζœ€εŽδΈ€εΈ§ */ + isLastFrame: boolean; + } + interface RecorderManager { + /** εΌ€ε§‹ε½•ιŸ³ */ + start(options?: RecorderManagerStartOptions): void; + /** ζš‚εœε½•ιŸ³ */ + pause(): void; + /** η»§η»­ε½•ιŸ³ */ + resume(): void; + /** εœζ­’ε½•ιŸ³ */ + stop(): void; + /** ε½•ιŸ³εΌ€ε§‹δΊ‹δ»Ά */ + onStart(callback?: () => void): void; + /** ε½•ιŸ³ζš‚εœδΊ‹δ»Ά */ + onPause(callback?: () => void): void; + /** ε½•ιŸ³ζ’ε€δΊ‹δ»Ά */ + onResume(callback?: () => void): void; + /** ε½•ιŸ³εœζ­’δΊ‹δ»ΆοΌŒδΌšε›žθ°ƒζ–‡δ»Άεœ°ε€ */ + onStop(callback?: (options: OnRecorderManagerStopOptions) => void): void; + /** ε·²ε½•εˆΆεŒζŒ‡εšεΈ§ε€§ε°ηš„ζ–‡δ»ΆοΌŒδΌšε›žθ°ƒε½•ιŸ³εˆ†η‰‡η»“ζžœζ•°ζγ€‚ε¦‚ζžœθΎη½δΊ† frameSize οΌŒεˆ™δΌšε›žθ°ƒζ­€δΊ‹δ»Ά */ + onFrameRecorded(callback?: (options: OnFrameRecordedOptions) => void): void; + /** ε½•ιŸ³ι”™θ――δΊ‹δ»Ά, δΌšε›žθ°ƒι”™θ――δΏ‘ζ― */ + onError(callback?: (err: ErrMsgResponse) => void): void; + } + /** + * θŽ·ε–ε…¨ε±€ε”―δΈ€ηš„ε½•ιŸ³η‘理器 recorderManager + * @version 1.6.0 + */ + function getRecorderManager(): RecorderManager; + // εͺ’体-----ιŸ³ι’‘ζ’­ζ”ΎζŽ§εˆΆ + interface PlayVoiceOptions extends BaseOptions { + /** ιœ€θ¦ζ’­ζ”Ύηš„θ―­ιŸ³ζ–‡δ»Άηš„ζ–‡δ»Άθ·―εΎ„ */ + filePath: string; + } + /** + * εΌ€ε§‹ζ’­ζ”Ύθ―­ιŸ³οΌŒεŒζ—Άεͺ允θΈδΈ€δΈͺθ―­ιŸ³ζ–‡δ»Άζ­£εœ¨ζ’­ζ”ΎοΌŒ + * ε¦‚ζžœε‰δΈ€δΈͺθ―­ιŸ³ζ–‡δ»ΆθΏ˜ζ²‘ζ’­ζ”ΎεŒοΌŒε°†δΈ­ζ–­ε‰δΈ€δΈͺθ―­ιŸ³ζ’­ζ”Ύγ€‚ + * @deprecated 1.6.0 + */ + function playVoice(options: PlayVoiceOptions): void; + /** + * ζš‚εœζ­£εœ¨ζ’­ζ”Ύηš„θ―­ιŸ³γ€‚ + * 再欑调用swan.playVoiceζ’­ζ”ΎεŒδΈ€δΈͺζ–‡δ»Άζ—ΆοΌŒδΌšδ»Žζš‚εœε€„εΌ€ε§‹ζ’­ζ”Ύγ€‚ + * ε¦‚ζžœζƒ³δ»Žε€΄εΌ€ε§‹ζ’­ζ”ΎοΌŒιœ€θ¦ε…ˆθ°ƒη”¨ swan.stopVoice。 + * @deprecated 1.6.0 + */ + function pauseVoice(): void; + /** + * η»“ζŸζ’­ζ”Ύθ―­ιŸ³γ€‚ + * @deprecated 1.6.0 + */ + function stopVoice(): void; + // εͺ’体-----ιŸ³δΉζ’­ζ”ΎζŽ§εˆΆ + interface BackgroundAudioPlayerState { + /** 选εšιŸ³ι’‘ηš„ι•ΏεΊ¦οΌˆε•δ½οΌšsοΌ‰οΌŒεͺζœ‰εœ¨ε½“ε‰ζœ‰ιŸ³δΉζ’­ζ”Ύζ—ΆθΏ”ε›ž */ + duration: number; + /** 选εšιŸ³ι’‘ηš„ζ’­ζ”Ύδ½η½οΌˆε•δ½οΌšsοΌ‰οΌŒεͺζœ‰εœ¨ε½“ε‰ζœ‰ιŸ³δΉζ’­ζ”Ύζ—ΆθΏ”ε›ž */ + currentPosition: number; + /** ζ’­ζ”ΎηŠΆζ€οΌˆ2οΌšζ²‘ζœ‰ιŸ³δΉεœ¨ζ’­ζ”ΎοΌŒ1οΌšζ’­ζ”ΎδΈ­οΌŒ0οΌšζš‚εœδΈ­οΌ‰ */ + status: number; + /** ιŸ³ι’‘ηš„δΈ‹θ½½θΏ›εΊ¦οΌˆζ•΄ζ•°οΌŒ80 代葨 80%οΌ‰οΌŒεͺζœ‰εœ¨ε½“ε‰ζœ‰ιŸ³δΉζ’­ζ”Ύζ—ΆθΏ”ε›ž */ + downloadPercent: number; + /** ζ­Œζ›²ζ•°ζι“ΎζŽ₯,εͺζœ‰εœ¨ε½“ε‰ζœ‰ιŸ³δΉζ’­ζ”Ύζ—ΆθΏ”ε›ž */ + dataUrl: string; + } + interface GetBackgroundAudioPlayerStateOptions extends BaseOptions { + /** ζŽ₯ε£θ°ƒη”¨ζˆεŠŸηš„ε›žθ°ƒε‡½ζ•° */ + success?(state: BackgroundAudioPlayerState): void; + /** ζŽ₯口调用倱θ΄₯ηš„ε›žθ°ƒε‡½ζ•° */ + fail?(): void; + /** ζŽ₯ε£θ°ƒη”¨η»“ζŸηš„ε›žθ°ƒε‡½ζ•°οΌˆθ°ƒη”¨ζˆεŠŸγ€ε€±θ΄₯ιƒ½δΌšζ‰§θ‘ŒοΌ‰ */ + complete?(): void; + } + /** + * θŽ·ε–ιŸ³δΉζ’­ζ”ΎηŠΆζ€γ€‚ + * @deprecated 1.2.0 + */ + function getBackgroundAudioPlayerState( + options: GetBackgroundAudioPlayerStateOptions + ): void; + interface PlayBackgroundAudioOptions extends BaseOptions { + /** ιŸ³δΉι“ΎζŽ₯ */ + dataUrl: string; + /** ιŸ³δΉζ ‡ι’˜ */ + title?: string; + /** 封青URL */ + coverImgUrl?: string; + } + /** + * ζ’­ζ”ΎιŸ³δΉοΌŒεŒζ—Άεͺθƒ½ζœ‰δΈ€ι¦–ιŸ³δΉζ­£εœ¨ζ’­ζ”Ύγ€‚ + * @deprecated 1.2.0 + */ + function playBackgroundAudio(options: PlayBackgroundAudioOptions): void; + /** + * ζš‚εœζ’­ζ”ΎιŸ³δΉγ€‚ + * @deprecated 1.2.0 + */ + function pauseBackgroundAudio(options?: PlayBackgroundAudioOptions): void; + interface SeekBackgroundAudioOptions extends BaseOptions { + /** 音乐位η½οΌŒε•δ½οΌšη§’ */ + position: number; + } + /** + * ζŽ§εˆΆιŸ³δΉζ’­ζ”ΎθΏ›εΊ¦γ€‚ + * @deprecated 1.2.0 + */ + function seekBackgroundAudio(options: SeekBackgroundAudioOptions): void; + /** + * εœζ­’ζ’­ζ”ΎιŸ³δΉγ€‚ + * @deprecated 1.2.0 + */ + function stopBackgroundAudio(options?: PlayBackgroundAudioOptions): void; + /** + * η›‘ε¬ιŸ³δΉζ’­ζ”Ύγ€‚ + * @deprecated 1.2.0 + */ + function onBackgroundAudioPlay(callback: () => void): void; + /** + * η›‘ε¬ιŸ³δΉζš‚εœγ€‚ + * @deprecated 1.2.0 + */ + function onBackgroundAudioPause(callback: () => void): void; + /** + * η›‘ε¬ιŸ³δΉεœζ­’γ€‚ + * @deprecated 1.2.0 + */ + function onBackgroundAudioStop(callback: () => void): void; + interface BackgroundAudioManager { + /** ε½“ε‰ιŸ³ι’‘ηš„ι•ΏεΊ¦οΌˆε•δ½οΌšsοΌ‰οΌŒεͺζœ‰εœ¨ε½“ε‰ζœ‰εˆζ³•ηš„ src ζ—ΆθΏ”ε›ž */ + readonly duration: number; + /** ε½“ε‰ιŸ³ι’‘ηš„ζ’­ζ”Ύδ½η½οΌˆε•δ½οΌšsοΌ‰οΌŒεͺζœ‰εœ¨ε½“ε‰ζœ‰εˆζ³•ηš„ src ζ—ΆθΏ”ε›ž */ + readonly currentTime: number; + /** ε½“ε‰ζ˜―ζ˜―ε¦ζš‚εœζˆ–εœζ­’ηŠΆζ€οΌŒtrue θ‘¨η€Ίζš‚εœζˆ–εœζ­’οΌŒfalse θ‘¨η€Ίζ­£εœ¨ζ’­ζ”Ύ */ + readonly paused: boolean; + /** ιŸ³ι’‘ηš„ζ•°ζζΊοΌŒι»˜θ€δΈΊη©Ίε­—η¬¦δΈ²οΌŒε½“θΎη½δΊ†ζ–°ηš„ src ζ—ΆοΌŒδΌšθ‡ͺεŠ¨εΌ€ε§‹ζ’­ζ”Ύ ,η›ε‰ζ”―ζŒηš„ζ ΌεΌζœ‰ m4a, aac, mp3, wav */ + src?: string; + /** ιŸ³ι’‘εΌ€ε§‹ζ’­ζ”Ύηš„δ½η½οΌˆε•δ½οΌšsοΌ‰ */ + startTime?: number; + /** ιŸ³ι’‘ηΌ“ε†²ηš„ζ—Άι—΄η‚ΉοΌŒδ»…δΏθ―ε½“ε‰ζ’­ζ”Ύζ—Άι—΄η‚Ήεˆ°ζ­€ζ—Άι—΄η‚Ήε†…εΉε·²ηΌ“冲。 是 */ + buffered: number; + /** ιŸ³ι’‘ζ ‡ι’˜οΌŒη”¨δΊŽεšεŽŸη”ŸιŸ³ι’‘ζ’­ζ”Ύε™¨ιŸ³ι’‘ζ ‡ι’˜γ€‚εŽŸη”ŸιŸ³ι’‘ζ’­ζ”Ύε™¨δΈ­ηš„εˆ†δΊ«εŠŸθƒ½οΌŒεˆ†δΊ«ε‡ΊεŽ»ηš„ε‘η‰‡ζ ‡ι’˜οΌŒδΉŸε°†δ½Ώη”¨θ―₯值。 */ + title?: string; + /** δΈ“θΎ‘εοΌŒεŽŸη”ŸιŸ³ι’‘ζ’­ζ”Ύε™¨δΈ­ηš„εˆ†δΊ«εŠŸθƒ½οΌŒεˆ†δΊ«ε‡ΊεŽ»ηš„ε‘η‰‡η€δ»‹οΌŒδΉŸε°†δ½Ώη”¨θ―₯ε€Ό */ + epname?: string; + /** ζ­Œζ‰‹εοΌŒεŽŸη”ŸιŸ³ι’‘ζ’­ζ”Ύε™¨δΈ­ηš„εˆ†δΊ«εŠŸθƒ½οΌŒεˆ†δΊ«ε‡ΊεŽ»ηš„ε‘η‰‡η€δ»‹οΌŒδΉŸε°†δ½Ώη”¨θ―₯ε€Ό */ + singer?: string; + /** 封青图urlοΌŒη”¨δΊŽεšεŽŸη”ŸιŸ³ι’‘ζ’­ζ”Ύε™¨θƒŒζ™―ε›Ύγ€‚εŽŸη”ŸιŸ³ι’‘ζ’­ζ”Ύε™¨δΈ­ηš„εˆ†δΊ«εŠŸθƒ½οΌŒεˆ†δΊ«ε‡ΊεŽ»ηš„ε‘η‰‡ι…ε›ΎεŠθƒŒζ™―δΉŸε°†δ½Ώη”¨θ―₯图。 */ + coverImgUrl?: string; + /** ζ’­ζ”Ύ */ + play(): void; + /** ζš‚εœ */ + pause(): void; + /** 停歒 */ + stop(): void; + /** θ·³θ½¬εˆ°ζŒ‡εšδ½η½οΌŒε•位 s */ + seek(position: number): void; + /** θƒŒζ™―ιŸ³ι’‘θΏ›ε…₯可δ»₯ζ’­ζ”ΎηŠΆζ€οΌŒδ½†δΈδΏθ―εŽι’ε―δ»₯桁畅播放 */ + onCanplay(callback: (res: ErrCodeResponse) => void): void; + /** θƒŒζ™―ιŸ³ι’‘ζ’­ζ”ΎδΊ‹δ»Ά */ + onPlay(callback: (res: ErrCodeResponse) => void): void; + /** θƒŒζ™―ιŸ³ι’‘ζš‚εœδΊ‹δ»Ά */ + onPause(callback: (res: ErrCodeResponse) => void): void; + /** θƒŒζ™―ιŸ³ι’‘εœζ­’δΊ‹δ»Ά */ + onStop(callback: (res: ErrCodeResponse) => void): void; + /** θƒŒζ™―ιŸ³ι’‘θ‡ͺη„Άζ’­ζ”Ύη»“ζŸδΊ‹δ»Ά */ + onEnded(callback: (res: ErrCodeResponse) => void): void; + /** θƒŒζ™―ιŸ³ι’‘ζ’­ζ”ΎθΏ›εΊ¦ζ›΄ζ–°δΊ‹δ»Ά */ + onTimeUpdate(callback: (res: ErrCodeResponse) => void): void; + /** θƒŒζ™―ιŸ³ι’‘ζ’­ζ”Ύι”™θ――δΊ‹δ»Ά */ + onError(callback: (res: ErrCodeResponse) => void): void; + /** ιŸ³ι’‘εŠ θ½½δΈ­δΊ‹δ»ΆοΌŒε½“ιŸ³ι’‘ε› δΈΊζ•°ζδΈθΆ³οΌŒιœ€θ¦εœδΈ‹ζ₯εŠ θ½½ζ—ΆδΌšθ§¦ε‘ */ + onWaiting(callback: (res: ErrCodeResponse) => void): void; + } + /** + * θŽ·ε–ε…¨ε±€ε”―δΈ€ηš„θƒŒζ™―ιŸ³ι’‘η‘理器 backgroundAudioManager。 + * @version 1.2.0 + */ + function getBackgroundAudioManager(): BackgroundAudioManager; + // εͺ’体-----ιŸ³ι’‘η»„δ»ΆζŽ§εˆΆ + /** + * audioContext ι€šθΏ‡ audioId θ·ŸδΈ€δΈͺ