From 1d1db373db08b243fcd5ee2cbcd4647e5ac81a8a Mon Sep 17 00:00:00 2001 From: Derek Finlinson Date: Tue, 24 Jul 2018 10:36:11 -0600 Subject: [PATCH 0001/1015] Change Xrm.Utility.lookupObjects to return array --- types/xrm/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index fdb6504e96..1b688c1e59 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -970,7 +970,7 @@ declare namespace Xrm { * Opens a lookup control to select one or more items. * @param lookupOptions Defines the options for opening the lookup dialog */ - lookupObjects(lookupOptions: LookupOptions): Async.PromiseLike; + lookupObjects(lookupOptions: LookupOptions): Async.PromiseLike; /** * Refreshes the parent grid containing the specified record. From c5a02fdae3d908c5276f0534acdbc38cac1be772 Mon Sep 17 00:00:00 2001 From: Konrad Mattheis Date: Tue, 2 Oct 2018 20:51:21 +0200 Subject: [PATCH 0002/1015] fix engineVersion result type closes #28133 closes #27984 --- types/qlik-engineapi/index.d.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/types/qlik-engineapi/index.d.ts b/types/qlik-engineapi/index.d.ts index dd9d761f56..2c2823c2dd 100644 --- a/types/qlik-engineapi/index.d.ts +++ b/types/qlik-engineapi/index.d.ts @@ -4063,7 +4063,7 @@ declare namespace EngineAPI { /** * Information about publishing and permissions. */ - qMeta: INxMeta; + qMeta: INxMetaTitleDescriptionTag; /** * Identifier and type of the dimension. @@ -6874,9 +6874,7 @@ declare namespace EngineAPI { } interface IQVersion { - qVersion: { - qComponentVersion: string; - }; + qComponentVersion: string; } interface IQConfig { @@ -7223,7 +7221,7 @@ declare namespace EngineAPI { * The apps are located in C:\Users\\Documents\Qlik\Sense\Apps. * @returns Path of the folder where the apps are stored. */ - getFolderItemsForPath(qPath: string): Promise; + getFolderItemsForPath(qPath: string): Promise; /** * Gets the list of all the script functions. @@ -9285,7 +9283,7 @@ declare namespace EngineAPI { * GenericDimensionListLayout width extend GenericBaseLayout */ interface IGenericDimensionListLayout extends IGenericBaseLayout { - qDimensionsListObject: IDimensionList; + qDimensionList: IDimensionList; } /** From 44054cedea3cdd8fa022f2f59b0507bdd032a90d Mon Sep 17 00:00:00 2001 From: Yishai Zehavi Date: Tue, 6 Nov 2018 12:43:25 +0200 Subject: [PATCH 0003/1015] Updated types to version 3 --- types/lolex/index.d.ts | 247 +++++++++++++++++++++++++++-------------- 1 file changed, 166 insertions(+), 81 deletions(-) diff --git a/types/lolex/index.d.ts b/types/lolex/index.d.ts index 1727c97ad3..7ad5c11898 100644 --- a/types/lolex/index.d.ts +++ b/types/lolex/index.d.ts @@ -1,10 +1,76 @@ -// Type definitions for lolex 2.1 +// Type definitions for lolex 3 // Project: https://github.com/sinonjs/lolex // Definitions by: Wim Looman // Josh Goldberg // Rogier Schouten +// Yishai Zehavi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/** + * Names of clock methods that may be faked by install. + */ +type FakeMethod = "setTimeout" | "clearTimeout" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "Date" | "nextTick" | "hrtime"; + +/** + * Global methods avaliable to every clock and also as standalone methods (inside `timers` global object). + */ +export interface GlobalTimers { + /** + * Schedules a callback to be fired once timeout milliseconds have ticked by. + * + * @param callback Callback to be fired. + * @param timeout How many ticks to wait to run the callback. + * @param args Any extra arguments to pass to the callback. + * @returns Time identifier for cancellation. + */ + setTimeout: (callback: () => void, timeout: number, ...args: any[]) => TTimerId; + + /** + * Clears a timer, as long as it was created using setTimeout. + * + * @param id Timer ID or object. + */ + clearTimeout: (id: TimerId) => void; + + /** + * Schedules a callback to be fired every time timeout milliseconds have ticked by. + * + * @param callback Callback to be fired. + * @param timeout How many ticks to wait between callbacks. + * @param args Any extra arguments to pass to the callback. + * @returns Time identifier for cancellation. + */ + setInterval: (callback: () => void, timeout: number, ...args: any[]) => TTimerId; + + /** + * Clears a timer, as long as it was created using setInterval. + * + * @param id Timer ID or object. + */ + clearInterval: (id: TTimerId) => void; + + /** + * Schedules the callback to be fired once 0 milliseconds have ticked by. + * + * @param callback Callback to be fired. + * @remarks You'll still have to call clock.tick() for the callback to fire. + * @remarks If called during a tick the callback won't fire until 1 millisecond has ticked by. + */ + setImmediate: (callback: () => void) => TTimerId; + + /** + * Clears a timer, as long as it was created using setImmediate. + * + * @param id Timer ID or object. + */ + clearImmediate: (id: TTimerId) => void; + + /** + * Implements the Date object but using this clock to provide the correct time. + */ + Date: typeof Date; +} + /** * Timer object used in node. */ @@ -25,102 +91,47 @@ export interface NodeTimer { */ export type TimerId = number | NodeTimer; -/** - * Lolex clock for a browser environment. - */ -type BrowserClock = LolexClock; - -/** - * Lolex clock for a Node environment. - */ -type NodeClock = LolexClock & { - /** - * Mimicks process.hrtime(). - * - * @param prevTime Previous system time to calculate time elapsed. - * @returns High resolution real time as [seconds, nanoseconds]. - */ - hrtime(prevTime?: [number, number]): [number, number]; -}; - -/** - * Clock object created by lolex. - */ -type Clock = BrowserClock | NodeClock; - -/** - * Names of clock methods that may be faked by install. - */ -type FakeMethod = "setTimeout" | "clearTimeout" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "Date" | "nextTick" | "hrtime"; - /** * Controls the flow of time. */ -export interface LolexClock { +export interface LolexClock extends GlobalTimers { /** * Current clock time. */ now: number; /** - * Implements the Date object but using this clock to provide the correct time. + * Don't know what this prop is for, but it was included in the clocks that `createClock` or + * `install` return (it is never used in the code, for now). */ - Date: typeof Date; + timeouts: {}; /** - * Schedules a callback to be fired once timeout milliseconds have ticked by. + * Maximum number of timers that will be run when calling runAll(). + */ + loopLimit: number; + + /** + * Schedule callback to run in the next animation frame. * * @param callback Callback to be fired. - * @param timeout How many ticks to wait to run the callback. - * @param args Any extra arguments to pass to the callback. - * @returns Time identifier for cancellation. + * @returns Request id. */ - setTimeout: (callback: () => any, timeout: number, ...args: any[]) => TTimerId; + requestAnimationFrame: (callback: (time: number) => void) => TTimerId; /** - * Clears a timer, as long as it was created using setTimeout. + * Cancel animation frame request. * - * @param id Timer ID or object. + * @param id The id returned from requestAnimationFrame method. */ - clearTimeout: (id: TTimerId) => void; + cancelAnimationFrame: (id: TTimerId) => void; - /** - * Schedules a callback to be fired every time timeout milliseconds have ticked by. - * - * @param callback Callback to be fired. - * @param timeout How many ticks to wait between callbacks. - * @param args Any extra arguments to pass to the callback. - * @returns Time identifier for cancellation. - */ - setInterval: (callback: () => any, timeout: number, ...args: any[]) => TTimerId; - - /** - * Clears a timer, as long as it was created using setInterval. - * - * @param id Timer ID or object. - */ - clearInterval: (id: TTimerId) => void; - - /** - * Schedules the callback to be fired once 0 milliseconds have ticked by. - * - * @param callback Callback to be fired. - * @remarks You'll still have to call clock.tick() for the callback to fire. - * @remarks If called during a tick the callback won't fire until 1 millisecond has ticked by. - */ - setImmediate: (callback: () => any) => TTimerId; - - /** - * Clears a timer, as long as it was created using setImmediate. - * - * @param id Timer ID or object. - */ - clearImmediate: (id: TTimerId) => void; - - /** - * Simulates process.nextTick(); - */ - nextTick: (callback: () => void) => void; + /** + * Get the number of waiting timers. + * + * @returns number of waiting timers. + */ + countTimers: () => number; /** * Advances the clock to the the moment of the first scheduled timer, firing it. @@ -134,6 +145,11 @@ export interface LolexClock { */ tick: (time: number | string) => void; + /** + * Removes all timers and tick without firing them and restore now to its original value. + */ + reset: () => void; + /** * Runs all pending timers until there are none remaining. * @@ -141,6 +157,11 @@ export interface LolexClock { */ runAll: () => void; + /** + * Advanced the clock to the next animation frame while firing all scheduled callbacks. + */ + runToFrame: () => void; + /** * Takes note of the last scheduled timer when it is run, and advances the clock to * that time firing callbacks as necessary. @@ -154,13 +175,62 @@ export interface LolexClock { * @remarks This affects the current time but it does not in itself cause timers to fire. */ setSystemTime: (now?: number | Date) => void; +} +/** + * Lolex clock for a browser environment. + */ +type BrowserClock = LolexClock & { + /** + * Mimics performance.now(). + */ + performance: { + now: () => number; + } +}; + +/** + * Lolex clock for a Node environment. + */ +type NodeClock = LolexClock & { + /** + * Mimicks process.hrtime(). + * + * @param prevTime Previous system time to calculate time elapsed. + * @returns High resolution real time as [seconds, nanoseconds]. + */ + hrtime(prevTime?: [number, number]): [number, number]; + + /** + * Mimics process.nextTick() explicitly dropping additional arguments. + */ + queueMicrotask: (callback: () => void) => void; + + /** + * Simulates process.nextTick(). + */ + nextTick: (callback: () => void) => void; + + /** + * Run all pending microtasks scheduled with nextTick. + */ + runMicrotasks: () => void; +}; + +/** + * Clock object created by lolex. + */ +type Clock = BrowserClock | NodeClock; + +type InstalledClock = Clock & { /** * Restores the original methods on the context that was passed to lolex.install, * or the native timers if no context was given. */ uninstall: () => void; -} + + methods: FakeMethod[]; +}; /** * Creates a clock. @@ -174,7 +244,6 @@ export interface LolexClock { */ export declare function createClock(now?: number | Date, loopLimit?: number): TClock; - export interface LolexInstallOpts { /** * Installs lolex onto the specified target context (default: global) @@ -215,6 +284,22 @@ export interface LolexInstallOpts { * * @param now Current time for the clock, as with lolex.createClock(). * @param toFake Names of methods that should be faked. - * @type TClock Type of clock to create. + * @type InstalledClock Type of clock to create. */ -export declare function install(opts?: LolexInstallOpts): TClock; +export declare function install(opts?: LolexInstallOpts): InstalledClock; + +export interface LolexWithContext { + timers: GlobalTimers; + createClock: (now?: number | Date, loopLimit?: number) => TClock; + install: (opts?: LolexInstallOpts) => InstalledClock; + withGlobal: (global: object) => LolexWithContext; +} + +/** + * Apply new context to lolex. + * + * @param global New context to apply like `window` (in browsers) or `global` (in node). + */ +export declare function withGlobal(global: object): LolexWithContext; + +export declare const timers: GlobalTimers; From c96f272c35599ad8f8aca46ad29f92d5da953a45 Mon Sep 17 00:00:00 2001 From: Yishai Zehavi Date: Tue, 6 Nov 2018 13:33:30 +0200 Subject: [PATCH 0004/1015] Added tests to version 3 --- types/lolex/lolex-tests.ts | 50 ++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/types/lolex/lolex-tests.ts b/types/lolex/lolex-tests.ts index f698eac3cc..56505c62e9 100644 --- a/types/lolex/lolex-tests.ts +++ b/types/lolex/lolex-tests.ts @@ -1,5 +1,17 @@ import lolex = require("lolex"); +const global: lolex.LolexWithContext = lolex.withGlobal({}); +const timers: lolex.GlobalTimers = lolex.timers; + +const lolexTimeout: lolex.TimerId = timers.setTimeout(() => {}, 42); +const lolexInterval: lolex.TimerId = timers.setInterval(() => {}, 42); +const lolexImmediate: lolex.TimerId = timers.setImmediate(() => {}); +const lolexDate: Date = new timers.Date(); + +timers.clearTimeout(lolexTimeout); +timers.clearInterval(lolexInterval); +timers.clearImmediate(lolexImmediate); + let browserClock: lolex.BrowserClock = lolex.createClock() as lolex.BrowserClock; let nodeClock: lolex.NodeClock = lolex.createClock() as lolex.NodeClock; @@ -16,7 +28,7 @@ lolex.createClock(new Date()); lolex.createClock(7, 9001); lolex.createClock(new Date(), 9001); -lolex.install({ +const installedClock = lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: 0, @@ -25,7 +37,7 @@ lolex.install({ toFake: ["setTimeout", "nextTick", "hrtime"] }); -lolex.install({ +lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: new Date(0), @@ -35,7 +47,10 @@ lolex.install({ }); const browserNow: number = browserClock.now; +const browserTimeouts: Object = browserClock.timeouts; +const browserLoopLimit: number = browserClock.loopLimit; const browserDate: Date = new browserClock.Date(); +const browserPerformanceNow: number = browserClock.performance.now(); const nodeNow: number = nodeClock.now; const nodeDate: Date = new nodeClock.Date(); @@ -43,30 +58,45 @@ const nodeDate: Date = new nodeClock.Date(); const browserTimeout: number = browserClock.setTimeout(() => {}, 7); const browserInterval: number = browserClock.setInterval(() => {}, 7); const browserImmediate: number = browserClock.setImmediate(() => {}); +const browserAnimationFrame: number = browserClock.requestAnimationFrame(() => {}); const nodeTimeout: lolex.NodeTimer = nodeClock.setTimeout(() => {}, 7); const nodeInterval: lolex.NodeTimer = nodeClock.setInterval(() => {}, 7); const nodeImmediate: lolex.NodeTimer = nodeClock.setImmediate(() => {}); +const nodeAnimationFrame: lolex.NodeTimer = nodeClock.requestAnimationFrame(() => {}); + +nodeTimeout.ref(); +nodeTimeout.unref(); browserClock.clearTimeout(browserTimeout); browserClock.clearInterval(browserInterval); browserClock.clearImmediate(browserImmediate); +browserClock.cancelAnimationFrame(browserAnimationFrame); nodeClock.clearTimeout(nodeTimeout); nodeClock.clearInterval(nodeInterval); nodeClock.clearImmediate(nodeImmediate); +nodeClock.cancelAnimationFrame(nodeAnimationFrame); browserClock.tick(7); browserClock.tick("08"); nodeClock.tick(7); -nodeClock.tick("08"); +nodeClock.tick("08:03"); browserClock.next(); nodeClock.next(); +browserClock.reset(); +nodeClock.reset(); + browserClock.runAll(); nodeClock.runAll(); +nodeClock.runMicrotasks(); + +browserClock.runToFrame(); +nodeClock.runToFrame(); + browserClock.runToLast(); nodeClock.runToLast(); @@ -79,9 +109,19 @@ nodeClock.setSystemTime(7); nodeClock.setSystemTime(new Date()); nodeClock.nextTick(() => undefined); +nodeClock.queueMicrotask(() => {}); -browserClock.uninstall(); -nodeClock.uninstall(); +const browserTimersCount: number = browserClock.countTimers(); +const nodeTimersCount: number = nodeClock.countTimers(); + +let [secs, nanos] = nodeClock.hrtime([0, 0]); +[secs, nanos] = nodeClock.hrtime(); + +// shows that typescript successfully infer the return values as numbers. +secs.toFixed(); +nanos.toExponential(); + +installedClock.uninstall(); // Clocks should be typed to have unbound method signatures that can be passed around const { clearTimeout } = browserClock; From 56c35cf65676ee1aba392d1a7f2209ae41c63e4a Mon Sep 17 00:00:00 2001 From: Yishai Zehavi Date: Tue, 6 Nov 2018 13:33:30 +0200 Subject: [PATCH 0005/1015] Added tests to version 3 --- types/lolex/index.d.ts | 4 +-- types/lolex/lolex-tests.ts | 50 ++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/types/lolex/index.d.ts b/types/lolex/index.d.ts index 7ad5c11898..d34f958eb9 100644 --- a/types/lolex/index.d.ts +++ b/types/lolex/index.d.ts @@ -292,7 +292,7 @@ export interface LolexWithContext { timers: GlobalTimers; createClock: (now?: number | Date, loopLimit?: number) => TClock; install: (opts?: LolexInstallOpts) => InstalledClock; - withGlobal: (global: object) => LolexWithContext; + withGlobal: (global: Object) => LolexWithContext; } /** @@ -300,6 +300,6 @@ export interface LolexWithContext { * * @param global New context to apply like `window` (in browsers) or `global` (in node). */ -export declare function withGlobal(global: object): LolexWithContext; +export declare function withGlobal(global: Object): LolexWithContext; export declare const timers: GlobalTimers; diff --git a/types/lolex/lolex-tests.ts b/types/lolex/lolex-tests.ts index f698eac3cc..56505c62e9 100644 --- a/types/lolex/lolex-tests.ts +++ b/types/lolex/lolex-tests.ts @@ -1,5 +1,17 @@ import lolex = require("lolex"); +const global: lolex.LolexWithContext = lolex.withGlobal({}); +const timers: lolex.GlobalTimers = lolex.timers; + +const lolexTimeout: lolex.TimerId = timers.setTimeout(() => {}, 42); +const lolexInterval: lolex.TimerId = timers.setInterval(() => {}, 42); +const lolexImmediate: lolex.TimerId = timers.setImmediate(() => {}); +const lolexDate: Date = new timers.Date(); + +timers.clearTimeout(lolexTimeout); +timers.clearInterval(lolexInterval); +timers.clearImmediate(lolexImmediate); + let browserClock: lolex.BrowserClock = lolex.createClock() as lolex.BrowserClock; let nodeClock: lolex.NodeClock = lolex.createClock() as lolex.NodeClock; @@ -16,7 +28,7 @@ lolex.createClock(new Date()); lolex.createClock(7, 9001); lolex.createClock(new Date(), 9001); -lolex.install({ +const installedClock = lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: 0, @@ -25,7 +37,7 @@ lolex.install({ toFake: ["setTimeout", "nextTick", "hrtime"] }); -lolex.install({ +lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: new Date(0), @@ -35,7 +47,10 @@ lolex.install({ }); const browserNow: number = browserClock.now; +const browserTimeouts: Object = browserClock.timeouts; +const browserLoopLimit: number = browserClock.loopLimit; const browserDate: Date = new browserClock.Date(); +const browserPerformanceNow: number = browserClock.performance.now(); const nodeNow: number = nodeClock.now; const nodeDate: Date = new nodeClock.Date(); @@ -43,30 +58,45 @@ const nodeDate: Date = new nodeClock.Date(); const browserTimeout: number = browserClock.setTimeout(() => {}, 7); const browserInterval: number = browserClock.setInterval(() => {}, 7); const browserImmediate: number = browserClock.setImmediate(() => {}); +const browserAnimationFrame: number = browserClock.requestAnimationFrame(() => {}); const nodeTimeout: lolex.NodeTimer = nodeClock.setTimeout(() => {}, 7); const nodeInterval: lolex.NodeTimer = nodeClock.setInterval(() => {}, 7); const nodeImmediate: lolex.NodeTimer = nodeClock.setImmediate(() => {}); +const nodeAnimationFrame: lolex.NodeTimer = nodeClock.requestAnimationFrame(() => {}); + +nodeTimeout.ref(); +nodeTimeout.unref(); browserClock.clearTimeout(browserTimeout); browserClock.clearInterval(browserInterval); browserClock.clearImmediate(browserImmediate); +browserClock.cancelAnimationFrame(browserAnimationFrame); nodeClock.clearTimeout(nodeTimeout); nodeClock.clearInterval(nodeInterval); nodeClock.clearImmediate(nodeImmediate); +nodeClock.cancelAnimationFrame(nodeAnimationFrame); browserClock.tick(7); browserClock.tick("08"); nodeClock.tick(7); -nodeClock.tick("08"); +nodeClock.tick("08:03"); browserClock.next(); nodeClock.next(); +browserClock.reset(); +nodeClock.reset(); + browserClock.runAll(); nodeClock.runAll(); +nodeClock.runMicrotasks(); + +browserClock.runToFrame(); +nodeClock.runToFrame(); + browserClock.runToLast(); nodeClock.runToLast(); @@ -79,9 +109,19 @@ nodeClock.setSystemTime(7); nodeClock.setSystemTime(new Date()); nodeClock.nextTick(() => undefined); +nodeClock.queueMicrotask(() => {}); -browserClock.uninstall(); -nodeClock.uninstall(); +const browserTimersCount: number = browserClock.countTimers(); +const nodeTimersCount: number = nodeClock.countTimers(); + +let [secs, nanos] = nodeClock.hrtime([0, 0]); +[secs, nanos] = nodeClock.hrtime(); + +// shows that typescript successfully infer the return values as numbers. +secs.toFixed(); +nanos.toExponential(); + +installedClock.uninstall(); // Clocks should be typed to have unbound method signatures that can be passed around const { clearTimeout } = browserClock; From 368c7a78cfba464d7551a27b5bd75fee57e5aa05 Mon Sep 17 00:00:00 2001 From: Yishai Zehavi Date: Thu, 8 Nov 2018 12:50:49 +0200 Subject: [PATCH 0006/1015] Updated InstalledClock type --- types/lolex/index.d.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/types/lolex/index.d.ts b/types/lolex/index.d.ts index d34f958eb9..35c4880a5b 100644 --- a/types/lolex/index.d.ts +++ b/types/lolex/index.d.ts @@ -222,7 +222,10 @@ type NodeClock = LolexClock & { */ type Clock = BrowserClock | NodeClock; -type InstalledClock = Clock & { +/** + * Additional methods that installed clock have. + */ +type InstalledMethods = { /** * Restores the original methods on the context that was passed to lolex.install, * or the native timers if no context was given. @@ -232,6 +235,13 @@ type InstalledClock = Clock & { methods: FakeMethod[]; }; +/** + * Clock object created by calling `install();`. + * + * @type TClock type of base clock (e.g BrowserClock). + */ +type InstalledClock = TClock & InstalledMethods; + /** * Creates a clock. * @@ -284,14 +294,14 @@ export interface LolexInstallOpts { * * @param now Current time for the clock, as with lolex.createClock(). * @param toFake Names of methods that should be faked. - * @type InstalledClock Type of clock to create. + * @type TClock Type of clock to create. */ -export declare function install(opts?: LolexInstallOpts): InstalledClock; +export declare function install(opts?: LolexInstallOpts): InstalledClock; export interface LolexWithContext { timers: GlobalTimers; createClock: (now?: number | Date, loopLimit?: number) => TClock; - install: (opts?: LolexInstallOpts) => InstalledClock; + install: (opts?: LolexInstallOpts) => InstalledClock; withGlobal: (global: Object) => LolexWithContext; } From d7f6e54c62affd4ede49dbb521e719b9babfa421 Mon Sep 17 00:00:00 2001 From: Yishai Zehavi Date: Thu, 8 Nov 2018 12:51:02 +0200 Subject: [PATCH 0007/1015] Updated tests --- types/lolex/lolex-tests.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/types/lolex/lolex-tests.ts b/types/lolex/lolex-tests.ts index 56505c62e9..7137ba261d 100644 --- a/types/lolex/lolex-tests.ts +++ b/types/lolex/lolex-tests.ts @@ -28,7 +28,10 @@ lolex.createClock(new Date()); lolex.createClock(7, 9001); lolex.createClock(new Date(), 9001); -const installedClock = lolex.install({ +// showing two ways to specify the exact clock type for `install()` method: + +// first way: passing the exact clock type to `install()`. +const browserInstalledClock = lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: 0, @@ -37,7 +40,8 @@ const installedClock = lolex.install({ toFake: ["setTimeout", "nextTick", "hrtime"] }); -lolex.install({ +// second way: specify type for the clock variable as InstallClock. +const nodeInstalledClock: lolex.InstalledClock = lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: new Date(0), @@ -121,7 +125,11 @@ let [secs, nanos] = nodeClock.hrtime([0, 0]); secs.toFixed(); nanos.toExponential(); -installedClock.uninstall(); +browserInstalledClock.performance.now(); +nodeInstalledClock.nextTick(() => {}); + +browserInstalledClock.uninstall(); +nodeInstalledClock.uninstall(); // Clocks should be typed to have unbound method signatures that can be passed around const { clearTimeout } = browserClock; From 37c539d61955892cdcf7f2539c54b690fa84e106 Mon Sep 17 00:00:00 2001 From: Yishai Zehavi Date: Thu, 8 Nov 2018 12:59:55 +0200 Subject: [PATCH 0008/1015] Fixed tests --- types/lolex/lolex-tests.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/types/lolex/lolex-tests.ts b/types/lolex/lolex-tests.ts index 7137ba261d..2a01dd5916 100644 --- a/types/lolex/lolex-tests.ts +++ b/types/lolex/lolex-tests.ts @@ -28,9 +28,6 @@ lolex.createClock(new Date()); lolex.createClock(7, 9001); lolex.createClock(new Date(), 9001); -// showing two ways to specify the exact clock type for `install()` method: - -// first way: passing the exact clock type to `install()`. const browserInstalledClock = lolex.install({ advanceTimeDelta: 20, loopLimit: 10, @@ -40,8 +37,7 @@ const browserInstalledClock = lolex.install({ toFake: ["setTimeout", "nextTick", "hrtime"] }); -// second way: specify type for the clock variable as InstallClock. -const nodeInstalledClock: lolex.InstalledClock = lolex.install({ +const nodeInstalledClock = lolex.install({ advanceTimeDelta: 20, loopLimit: 10, now: new Date(0), From 8a7c70eb95d7727b712acab61e02dbdf3705afde Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Wed, 21 Nov 2018 19:14:37 -0800 Subject: [PATCH 0009/1015] Updated to clarify versioning behavior Fixed a few things with version-related documentation: * clarified the relationship of typings package version vs. library versions * explained how package versions and library versions can get out of sync * fixed broken links in major-version-upgrade section * clarified major-version-upgrade section See #25677 for more discussion and background for these changes. --- README.md | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9a31d73da1..8663bbb140 100644 --- a/README.md +++ b/README.md @@ -256,14 +256,43 @@ If the standard is still a draft, it belongs here. Use a name beginning with `dom-` and include a link to the standard as the "Project" link in the header. When it graduates draft mode, we may remove it from DefinitelyTyped and deprecate the associated `@types` package. -#### I want to update a package to a new major version +#### How do DefinitelyTyped package versions relate to versions of the corresponding library? -If you intend to continue updating the older version of the package, you may create a new subfolder with the current version e.g. `v2`, and copy existing files to it. If so, you will need to: +_NOTE: The discussion in this section assumes familiarity with [Semantic versioning](https://semver.org/)_ + +Each DefinitelyTyped package is versioned when published to NPM. The [automated tools](https://github.com/Microsoft/types-publisher) that publish typings packages to NPM will set the typings package's version using the version number listed in the first line of the typings file. For example, below is the first few lines of the latest (as of late 2018) [node.js typings file](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts) for node.js library version `10.12`. Because this version is included in the typings file, the NPM version of the `@types/node` package will also be `10.12`: + +```javascript +// Type definitions for Node.js 10.12 +// Project: http://nodejs.org/ +// Definitions by: Microsoft TypeScript +// DefinitelyTyped +// Alberto Schiabel +``` + +Sometimes typings versions and library versions can get out of sync. Below are a few common reasons why, in order of how much they inconvenience users of a library. Only the last case is typically problematic. + +* The patch version of the typings package is incremented every time an updated typings file is published for the same major and minor version. For example, a library may have only published `2.3.0` but the typings package might have gone through several revisions so its version would be `2.3.4`. If the library is later updated to `2.3.6` without any type updates needed, then the typings version would remain `2.3.4`. +* If a minor release adds new features that don't impact the type system, then there's no need to publish an updated typings file. In cases like this, updates are often skipped to the typings file. For example, imagine a contrived example of a library that formats only integers in its `2.0` release. If a `2.1` release of the library adds the capability to format floating point numbers too without changing API type signatures, then the typings version might remain `2.1.3` even as the library goes to `2.2.0`. +* Users who are updating typings for a library sometimes forget to increment the typings version to match the library version. This doesn't usually result in any problems because `npm update` will usually pick the latest typings version, although it may be confusing for users because they might assume that a library update is missing types that are really present. +* It's common for typings to lag behind library updates because it's often library users, not maintainers, who update DefinitelyTyped when new library features are released. So there may be a lag of days, weeks, or even months before a helpful community member sends a PR to update the typings for a new library release. + +:exclamation:If you're updating the typings for a library version, always set the major/minor version in the first line of the typings file to match the library version that you're documenting!:exclamation: + +#### If a library is updated to a new major version with breaking changes, how should I update its typings package? + +[Semantic versioning](https://semver.org/) requires that versions with breaking changes must increment the major version number. For example, a library that removes a publicly exported function after its `3.5.8` release must bump its version to `4.0.0` in its next release. Furthermore, when the library's `4.0.0` release is out, its DefinitelyTyped typings should also be updated to `4.0.0`, including any breaking changes to the library's API. + +Many libraries have a large installed base of developers (including mainatiners of other packages using that library as a dependency) who who won't move right away to a new version that has breaking changes, because it might be months until a maintainer has time to rewrite code to adapt to the new version. In the meantime, users of old library versions still may want to udpate typings for older versions. + +If you intend to continue updating the older version of the typings package, you may create a new subfolder (e.g. `/v2/`) named for the current (soon to be "old") version, and copy existing files from the current version to it. + +Because the root folder should always contain the typings for the latest ("new") version, you'll need to make a few changes to the files in your old-version subdirectory to ensure that relative path references point to the subdirectory, not the root. 1. Update the relative paths in `tsconfig.json` as well as `tslint.json`. 2. Add path mapping rules to ensure that tests are running against the intended version. -For example [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like: +For example, the [`history`](https://github.com/ReactTraining/history/) library introduced breaking changes between version `2.x` and `3.x`. Many developers waited a while to update their `package.json` to depend on version `3.x` of `history`. Therefore, there's a `v2` folder inside the history repository that contains typings for the older version. The [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like: ```json { @@ -281,10 +310,9 @@ For example [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/Defi } ``` -If there are other packages on DefinitelyTyped that are incompatible with the new version, you will need to add path mappings to the old version. You will also need to do this for packages depending on packages depending on the old version. +If there are other packages in DefinitelyTyped that are incompatible with the new version, you will need to add path mappings to the old version. You will also need to do this recursively for packages depending on packages depending on the old version. -For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`; -transitively `react-router-bootstrap` (which depends on `react-router`) also adds a path mapping in its [tsconfig.json](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router-bootstrap/tsconfig.json). +For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router/v2/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`. Transitively, `react-router-bootstrap` (which depends on `react-router`) also needed to add the same path mapping (`"history": [ "history/v2" ]`) in its `tsconfig.json` until its `react-router` dependency was udpated to the latest version. Also, `/// ` will not work with path mapping, so dependencies must use `import`. From 30c8898e6866fd6820a75998616de91e88fa9207 Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Fri, 23 Nov 2018 18:17:19 -0800 Subject: [PATCH 0010/1015] Changes in response to @Flarna review --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8663bbb140..aee5a1d07e 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ When it graduates draft mode, we may remove it from DefinitelyTyped and deprecat _NOTE: The discussion in this section assumes familiarity with [Semantic versioning](https://semver.org/)_ -Each DefinitelyTyped package is versioned when published to NPM. The [automated tools](https://github.com/Microsoft/types-publisher) that publish typings packages to NPM will set the typings package's version using the version number listed in the first line of the typings file. For example, below is the first few lines of the latest (as of late 2018) [node.js typings file](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts) for node.js library version `10.12`. Because this version is included in the typings file, the NPM version of the `@types/node` package will also be `10.12`: +Each DefinitelyTyped package is versioned when published to NPM. The [automated tools](https://github.com/Microsoft/types-publisher) that publish typings packages to NPM will set the typings package's version using the version number listed in the first line of the typings file. For example, below are the first few lines of the latest (as of late 2018) [node.js typings file](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts) for node.js library versions `10.12.x`. ```javascript // Type definitions for Node.js 10.12 @@ -270,11 +270,13 @@ Each DefinitelyTyped package is versioned when published to NPM. The [automated // Alberto Schiabel ``` +Because `10.12` is at the end the first line, the NPM version of the `@types/node` package will also be `10.12.x`. Note that the first-line comment in the typings file should only contaiin major/minor versions (e.g. `10.12`) and should not contain a patch version (e.g. `10.12.4`). This is because only the major and minor release numbers are aligned between library packages and typings packages. The patch release number of the typings package (e.g. `.0` in `10.12.0`) is initialized to zero by DefinitelyTyped and is incremented each time a new `@types/node` package is published to NPM for the same major/minor version of the corresponding library. + Sometimes typings versions and library versions can get out of sync. Below are a few common reasons why, in order of how much they inconvenience users of a library. Only the last case is typically problematic. -* The patch version of the typings package is incremented every time an updated typings file is published for the same major and minor version. For example, a library may have only published `2.3.0` but the typings package might have gone through several revisions so its version would be `2.3.4`. If the library is later updated to `2.3.6` without any type updates needed, then the typings version would remain `2.3.4`. -* If a minor release adds new features that don't impact the type system, then there's no need to publish an updated typings file. In cases like this, updates are often skipped to the typings file. For example, imagine a contrived example of a library that formats only integers in its `2.0` release. If a `2.1` release of the library adds the capability to format floating point numbers too without changing API type signatures, then the typings version might remain `2.1.3` even as the library goes to `2.2.0`. -* Users who are updating typings for a library sometimes forget to increment the typings version to match the library version. This doesn't usually result in any problems because `npm update` will usually pick the latest typings version, although it may be confusing for users because they might assume that a library update is missing types that are really present. +* As noted above, the patch version of the typings package is unrelated to the library patch version. This allows DefinitelyTyped to safely update typings for the same major/minor version of a library. +* If a minor release adds new features that don't impact the type system, then there's no need to publish an updated typings file. In cases like this, updates are often skipped to the typings file. For example, imagine a contrived example of a library that formats only integers in its `2.0` release. If a `2.1` release of the library adds the capability to format floating point numbers too without changing API type signatures, then the typings version might remain `2.0.3` even as the library goes to `2.1.0`. +* Users who are updating typings for a library sometimes forget to increment the typings version to match the library version. This doesn't usually result in any problems because `npm update` will usually pick the latest typings version, although it may be confusing for users because they might assume that a library update is missing types that are really present. It will also cause problems when libraries are (see below) updated to a new major release with breaking changes, because users won't know which typings version is the right one to use for older versions of the library. * It's common for typings to lag behind library updates because it's often library users, not maintainers, who update DefinitelyTyped when new library features are released. So there may be a lag of days, weeks, or even months before a helpful community member sends a PR to update the typings for a new library release. :exclamation:If you're updating the typings for a library version, always set the major/minor version in the first line of the typings file to match the library version that you're documenting!:exclamation: @@ -283,7 +285,7 @@ Sometimes typings versions and library versions can get out of sync. Below are a [Semantic versioning](https://semver.org/) requires that versions with breaking changes must increment the major version number. For example, a library that removes a publicly exported function after its `3.5.8` release must bump its version to `4.0.0` in its next release. Furthermore, when the library's `4.0.0` release is out, its DefinitelyTyped typings should also be updated to `4.0.0`, including any breaking changes to the library's API. -Many libraries have a large installed base of developers (including mainatiners of other packages using that library as a dependency) who who won't move right away to a new version that has breaking changes, because it might be months until a maintainer has time to rewrite code to adapt to the new version. In the meantime, users of old library versions still may want to udpate typings for older versions. +Many libraries have a large installed base of developers (including mainatiners of other packages using that library as a dependency) who won't move right away to a new version that has breaking changes, because it might be months until a maintainer has time to rewrite code to adapt to the new version. In the meantime, users of old library versions still may want to udpate typings for older versions. If you intend to continue updating the older version of the typings package, you may create a new subfolder (e.g. `/v2/`) named for the current (soon to be "old") version, and copy existing files from the current version to it. @@ -292,7 +294,7 @@ Because the root folder should always contain the typings for the latest ("new") 1. Update the relative paths in `tsconfig.json` as well as `tslint.json`. 2. Add path mapping rules to ensure that tests are running against the intended version. -For example, the [`history`](https://github.com/ReactTraining/history/) library introduced breaking changes between version `2.x` and `3.x`. Many developers waited a while to update their `package.json` to depend on version `3.x` of `history`. Therefore, there's a `v2` folder inside the history repository that contains typings for the older version. The [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like: +For example, the [`history`](https://github.com/ReactTraining/history/) library introduced breaking changes between version `2.x` and `3.x`. Many developers waited a while to update their `package.json` to depend on version `3.x` of `history`. Therefore, a maintainer of the typings for this library added a `v2` folder inside the history repository that contains typings for the older version. The [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like: ```json { From 60a7ec20eebfbe1c0c98100a718e1422dfdeb685 Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Tue, 4 Dec 2018 12:26:57 -0800 Subject: [PATCH 0011/1015] Updated in response to @DanielRosenwasser feedback Thanks @DanielRosenwasser for feedback! Here's what's different: * Updated typos: contaiin, udpated, udpate, mainatiners * One sentence per line, except bullet points where adding a newline will show up in user-visible text (GitHub markdown doesn't ignore line breaks in bullet points) * Removed "typings", replaced with either "type definition(s)" or "type definition package" depending on context Happy to make more edits, just let me know. --- README.md | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index aee5a1d07e..650cecd1d5 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,9 @@ When it graduates draft mode, we may remove it from DefinitelyTyped and deprecat _NOTE: The discussion in this section assumes familiarity with [Semantic versioning](https://semver.org/)_ -Each DefinitelyTyped package is versioned when published to NPM. The [automated tools](https://github.com/Microsoft/types-publisher) that publish typings packages to NPM will set the typings package's version using the version number listed in the first line of the typings file. For example, below are the first few lines of the latest (as of late 2018) [node.js typings file](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts) for node.js library versions `10.12.x`. +Each DefinitelyTyped package is versioned when published to NPM. +The [automated tools](https://github.com/Microsoft/types-publisher) that publish type declaration packages to NPM will set the type declaration package's version using the version number listed in the first line of its `index.d.ts` file. +For example, below are the first few lines of the latest (as of late 2018) [node.js type declarations](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts) for node.js library versions `10.12.x`. ```javascript // Type definitions for Node.js 10.12 @@ -270,31 +272,42 @@ Each DefinitelyTyped package is versioned when published to NPM. The [automated // Alberto Schiabel ``` -Because `10.12` is at the end the first line, the NPM version of the `@types/node` package will also be `10.12.x`. Note that the first-line comment in the typings file should only contaiin major/minor versions (e.g. `10.12`) and should not contain a patch version (e.g. `10.12.4`). This is because only the major and minor release numbers are aligned between library packages and typings packages. The patch release number of the typings package (e.g. `.0` in `10.12.0`) is initialized to zero by DefinitelyTyped and is incremented each time a new `@types/node` package is published to NPM for the same major/minor version of the corresponding library. +Because `10.12` is at the end the first line, the NPM version of the `@types/node` package will also be `10.12.x`. +Note that the first-line comment in the `index.d.ts` file should only contain major/minor versions (e.g. `10.12`) and should not contain a patch version (e.g. `10.12.4`). +This is because only the major and minor release numbers are aligned between library packages and type declaration packages. +The patch release number of the type declaration package (e.g. `.0` in `10.12.0`) is initialized to zero by DefinitelyTyped and is incremented each time a new `@types/node` package is published to NPM for the same major/minor version of the corresponding library. -Sometimes typings versions and library versions can get out of sync. Below are a few common reasons why, in order of how much they inconvenience users of a library. Only the last case is typically problematic. +Sometimes type declaration package versions and library package versions can get out of sync. +Below are a few common reasons why, in order of how much they inconvenience users of a library. +Only the last case is typically problematic. -* As noted above, the patch version of the typings package is unrelated to the library patch version. This allows DefinitelyTyped to safely update typings for the same major/minor version of a library. -* If a minor release adds new features that don't impact the type system, then there's no need to publish an updated typings file. In cases like this, updates are often skipped to the typings file. For example, imagine a contrived example of a library that formats only integers in its `2.0` release. If a `2.1` release of the library adds the capability to format floating point numbers too without changing API type signatures, then the typings version might remain `2.0.3` even as the library goes to `2.1.0`. -* Users who are updating typings for a library sometimes forget to increment the typings version to match the library version. This doesn't usually result in any problems because `npm update` will usually pick the latest typings version, although it may be confusing for users because they might assume that a library update is missing types that are really present. It will also cause problems when libraries are (see below) updated to a new major release with breaking changes, because users won't know which typings version is the right one to use for older versions of the library. -* It's common for typings to lag behind library updates because it's often library users, not maintainers, who update DefinitelyTyped when new library features are released. So there may be a lag of days, weeks, or even months before a helpful community member sends a PR to update the typings for a new library release. +* As noted above, the patch version of the type declaration package is unrelated to the library patch version. This allows DefinitelyTyped to safely update type declarations for the same major/minor version of a library. +* If a minor release adds new features that don't impact the type system, then there's no need to publish updated type declarations. In cases like this, updates are often skipped to the type declaration package. For example, imagine a contrived example of a library that formats only integers in its `2.0` release. If a `2.1` release of the library adds the capability to format floating point numbers too without changing API type signatures, then the type declaration package version might remain `2.0.3` even as the library goes to `2.1.0`. +* Users who are updating type declarations for a library sometimes forget to increment the type declaration package's version to match the library version. This doesn't usually result in any problems because `npm update` will usually pick the latest type declaration package version, although it may be confusing for users because they might assume that a library update is missing types that are really present. It will also cause problems when libraries are (see below) updated to a new major release with breaking changes, because users won't know which type declaration package version is the right one to use for older versions of the library. +* It's common for type declaration package updates to lag behind library updates because it's often library users, not maintainers, who update DefinitelyTyped when new library features are released. So there may be a lag of days, weeks, or even months before a helpful community member sends a PR to update the type declaration package for a new library release. -:exclamation:If you're updating the typings for a library version, always set the major/minor version in the first line of the typings file to match the library version that you're documenting!:exclamation: +:exclamation:If you're updating type declarations for a library, always set the major/minor version in the first line of `index.d.ts` to match the library version that you're documenting!:exclamation: -#### If a library is updated to a new major version with breaking changes, how should I update its typings package? +#### If a library is updated to a new major version with breaking changes, how should I update its type declaration package? -[Semantic versioning](https://semver.org/) requires that versions with breaking changes must increment the major version number. For example, a library that removes a publicly exported function after its `3.5.8` release must bump its version to `4.0.0` in its next release. Furthermore, when the library's `4.0.0` release is out, its DefinitelyTyped typings should also be updated to `4.0.0`, including any breaking changes to the library's API. +[Semantic versioning](https://semver.org/) requires that versions with breaking changes must increment the major version number. +For example, a library that removes a publicly exported function after its `3.5.8` release must bump its version to `4.0.0` in its next release. +Furthermore, when the library's `4.0.0` release is out, its DefinitelyTyped type declaration package should also be updated to `4.0.0`, including any breaking changes to the library's API. -Many libraries have a large installed base of developers (including mainatiners of other packages using that library as a dependency) who won't move right away to a new version that has breaking changes, because it might be months until a maintainer has time to rewrite code to adapt to the new version. In the meantime, users of old library versions still may want to udpate typings for older versions. +Many libraries have a large installed base of developers (including maintainers of other packages using that library as a dependency) who won't move right away to a new version that has breaking changes, because it might be months until a maintainer has time to rewrite code to adapt to the new version. +In the meantime, users of old library versions still may want to update type declarations for older versions. -If you intend to continue updating the older version of the typings package, you may create a new subfolder (e.g. `/v2/`) named for the current (soon to be "old") version, and copy existing files from the current version to it. +If you intend to continue updating the older version of a library's type declarations, you may create a new subfolder (e.g. `/v2/`) named for the current (soon to be "old") version, and copy existing files from the current version to it. -Because the root folder should always contain the typings for the latest ("new") version, you'll need to make a few changes to the files in your old-version subdirectory to ensure that relative path references point to the subdirectory, not the root. +Because the root folder should always contain the type declarations for the latest ("new") version, you'll need to make a few changes to the files in your old-version subdirectory to ensure that relative path references point to the subdirectory, not the root. 1. Update the relative paths in `tsconfig.json` as well as `tslint.json`. 2. Add path mapping rules to ensure that tests are running against the intended version. -For example, the [`history`](https://github.com/ReactTraining/history/) library introduced breaking changes between version `2.x` and `3.x`. Many developers waited a while to update their `package.json` to depend on version `3.x` of `history`. Therefore, a maintainer of the typings for this library added a `v2` folder inside the history repository that contains typings for the older version. The [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like: +For example, the [`history`](https://github.com/ReactTraining/history/) library introduced breaking changes between version `2.x` and `3.x`. +Many developers waited a while to update their `package.json` to depend on version `3.x` of `history`. +Therefore, a maintainer of the type declarations for this library added a `v2` folder inside the history repository that contains type declarations for the older version. +The [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like: ```json { @@ -312,9 +325,11 @@ For example, the [`history`](https://github.com/ReactTraining/history/) library } ``` -If there are other packages in DefinitelyTyped that are incompatible with the new version, you will need to add path mappings to the old version. You will also need to do this recursively for packages depending on packages depending on the old version. +If there are other packages in DefinitelyTyped that are incompatible with the new version, you will need to add path mappings to the old version. +You will also need to do this recursively for packages depending on packages depending on the old version. -For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router/v2/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`. Transitively, `react-router-bootstrap` (which depends on `react-router`) also needed to add the same path mapping (`"history": [ "history/v2" ]`) in its `tsconfig.json` until its `react-router` dependency was udpated to the latest version. +For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router/v2/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`. +Transitively, `react-router-bootstrap` (which depends on `react-router`) also needed to add the same path mapping (`"history": [ "history/v2" ]`) in its `tsconfig.json` until its `react-router` dependency was updated to the latest version. Also, `/// ` will not work with path mapping, so dependencies must use `import`. From f8c68f6b3e2113dda0ad9564eec96463da0d727f Mon Sep 17 00:00:00 2001 From: Antoine Brault Date: Wed, 5 Dec 2018 10:09:58 -0500 Subject: [PATCH 0012/1015] [jest] add type inference --- types/expect-puppeteer/index.d.ts | 2 +- types/jest-axe/index.d.ts | 2 +- types/jest-image-snapshot/index.d.ts | 2 +- types/jest-in-case/index.d.ts | 2 +- types/jest-in-case/jest-in-case-tests.ts | 8 +-- types/jest-json-schema/index.d.ts | 2 +- types/jest-matchers/index.d.ts | 2 +- types/jest-plugin-context/index.d.ts | 2 +- types/jest-specific-snapshot/index.d.ts | 2 +- types/jest-when/index.d.ts | 18 +++--- types/jest-when/jest-when-tests.ts | 16 +++-- types/jest/index.d.ts | 63 ++++++++++---------- types/jest/jest-tests.ts | 56 +++++++++++++---- types/jest/tsconfig.json | 1 + types/storybook__addon-storyshots/index.d.ts | 2 +- 15 files changed, 105 insertions(+), 75 deletions(-) diff --git a/types/expect-puppeteer/index.d.ts b/types/expect-puppeteer/index.d.ts index b77bc948bd..018e342ce8 100644 --- a/types/expect-puppeteer/index.d.ts +++ b/types/expect-puppeteer/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Josh Goldberg // Tanguy Krotoff // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 /// diff --git a/types/jest-axe/index.d.ts b/types/jest-axe/index.d.ts index 60375e3605..506236773f 100644 --- a/types/jest-axe/index.d.ts +++ b/types/jest-axe/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/nickcolley/jest-axe // Definitions by: Josh Goldberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +// TypeScript Version: 3.0 /// diff --git a/types/jest-image-snapshot/index.d.ts b/types/jest-image-snapshot/index.d.ts index c15e435cc9..8eeff20990 100644 --- a/types/jest-image-snapshot/index.d.ts +++ b/types/jest-image-snapshot/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/americanexpress/jest-image-snapshot#readme // Definitions by: Janeene Beeforth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// diff --git a/types/jest-in-case/index.d.ts b/types/jest-in-case/index.d.ts index 02d7d08af9..9762bc39d3 100644 --- a/types/jest-in-case/index.d.ts +++ b/types/jest-in-case/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/thinkmill/jest-in-case#readme // Definitions by: Geovani de Souza // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// /// diff --git a/types/jest-in-case/jest-in-case-tests.ts b/types/jest-in-case/jest-in-case-tests.ts index 283ade76c1..6af60a5fd4 100644 --- a/types/jest-in-case/jest-in-case-tests.ts +++ b/types/jest-in-case/jest-in-case-tests.ts @@ -11,8 +11,8 @@ function subtract(minuend: number, subtrahend: number) { } beforeEach(() => { - jest.spyOn(global, 'describe').mockImplementation((title, fn) => fn()); - jest.spyOn(global, 'test').mockImplementation((name, fn) => fn()); + jest.spyOn(global, 'describe').mockImplementation((title, fn) => jest.fn()); + jest.spyOn(global, 'test').mockImplementation((name, fn) => jest.fn()); global.test.skip = jest.fn((name, fn) => fn()); global.test.only = jest.fn((name, fn) => fn()); }); @@ -54,8 +54,8 @@ test('array', () => { }); test('object', () => { - jest.spyOn(global, 'describe').mockImplementation((title, fn) => fn()); - jest.spyOn(global, 'test').mockImplementation((name, fn) => fn()); + jest.spyOn(global, 'describe').mockImplementation((title, fn) => jest.fn()); + jest.spyOn(global, 'test').mockImplementation((name, fn) => jest.fn()); const title = 'add(augend, addend)'; diff --git a/types/jest-json-schema/index.d.ts b/types/jest-json-schema/index.d.ts index 67f1c51f7e..b2133526dc 100644 --- a/types/jest-json-schema/index.d.ts +++ b/types/jest-json-schema/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/americanexpress/jest-json-schema#readme // Definitions by: Igor Korolev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// import * as ajv from "ajv"; diff --git a/types/jest-matchers/index.d.ts b/types/jest-matchers/index.d.ts index 3b028f8929..705f993ea3 100644 --- a/types/jest-matchers/index.d.ts +++ b/types/jest-matchers/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/facebook/jest#readme // Definitions by: Joscha Feth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// export = expect; diff --git a/types/jest-plugin-context/index.d.ts b/types/jest-plugin-context/index.d.ts index da2698b78e..814b334b12 100644 --- a/types/jest-plugin-context/index.d.ts +++ b/types/jest-plugin-context/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/negativetwelve/jest-plugins/tree/master/packages/jest-plugin-context // Definitions by: Jonas Heinrich // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// diff --git a/types/jest-specific-snapshot/index.d.ts b/types/jest-specific-snapshot/index.d.ts index 61a65a416a..0e0a43d895 100644 --- a/types/jest-specific-snapshot/index.d.ts +++ b/types/jest-specific-snapshot/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/igor-dv/jest-specific-snapshot#readme // Definitions by: Janeene Beeforth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 /// diff --git a/types/jest-when/index.d.ts b/types/jest-when/index.d.ts index af62a95830..fbd938b5ff 100644 --- a/types/jest-when/index.d.ts +++ b/types/jest-when/index.d.ts @@ -2,21 +2,17 @@ // Project: https://github.com/timkindberg/jest-when#readme // Definitions by: Alden Taylor // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 /// -export interface PartialMockInstance { - mockReturnValue: jest.MockInstance['mockReturnValue']; -} +export type PartialMockInstance = Pick, 'mockReturnValue' | 'mockReturnValueOnce' | 'mockResolvedValue' + | 'mockResolvedValueOnce' | 'mockRejectedValue' | 'mockRejectedValueOnce'>; -export interface When { - (fn: jest.Mocked | jest.Mock): When; - // due to no-unnecessary-generics lint rule, the generics have been replaced with 'any' - // calledWith(...matchers: any[]): PartialMockInstance; - // expectCalledWith(...matchers: any[]): PartialMockInstance; - calledWith(...matchers: any[]): PartialMockInstance; - expectCalledWith(...matchers: any[]): PartialMockInstance; +export interface When { + (fn: jest.Mock): When; + calledWith(...matchers: Y): PartialMockInstance; + expectCalledWith(...matchers: Y): PartialMockInstance; } export const when: When; diff --git a/types/jest-when/jest-when-tests.ts b/types/jest-when/jest-when-tests.ts index 13da65928d..70e0041341 100644 --- a/types/jest-when/jest-when-tests.ts +++ b/types/jest-when/jest-when-tests.ts @@ -31,16 +31,20 @@ describe('mock-when test', () => { it('Supports compound declarations:', () => { const fn = jest.fn(); - when(fn).calledWith(1).mockReturnValue('no'); + when(fn).calledWith(1).mockReturnValueOnce('no').mockReturnValue('yes'); when(fn).calledWith(2).mockReturnValue('way?'); - when(fn).calledWith(3).mockReturnValue('yes'); - when(fn).calledWith(4).mockReturnValue('way!'); + when(fn).calledWith(3).mockResolvedValueOnce('no'); + when(fn).calledWith(3).mockResolvedValue('yes'); + when(fn).calledWith(4).mockRejectedValueOnce('no'); + when(fn).calledWith(4).mockRejectedValue('yes'); expect(fn(1)).toEqual('no'); + expect(fn(1)).toEqual('yes'); expect(fn(2)).toEqual('way?'); - expect(fn(3)).toEqual('yes'); - expect(fn(4)).toEqual('way!'); - expect(fn(5)).toEqual(undefined); + expect(fn(3)).resolves.toEqual('no'); + expect(fn(3)).resolves.toEqual('yes'); + expect(fn(4)).rejects.toEqual('no'); + expect(fn(4)).rejects.toEqual('yes'); }); it('Assert the args:', () => { diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index d434b5e198..f303230f76 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -17,8 +17,9 @@ // Martin Hochel // Sebastian Sebald // Andy +// Antoine Brault // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.0 declare var beforeAll: jest.Lifecycle; declare var beforeEach: jest.Lifecycle; @@ -35,6 +36,8 @@ declare var xtest: jest.It; declare const expect: jest.Expect; +type ArgsType = T extends (...args: infer A) => any ? A : never; + interface NodeRequire { /** * Returns the actual module instead of a mock, bypassing all checks on @@ -110,11 +113,7 @@ declare namespace jest { /** * Creates a mock function. Optionally takes a mock implementation. */ - function fn(implementation: (...args: any[]) => T): Mock; - /** - * Creates a mock function. Optionally takes a mock implementation. - */ - function fn(implementation?: (...args: any[]) => any): Mock; + function fn(implementation?: (...args: Y) => T): Mock; /** * Use the automatic mocking system to generate a mocked version of the given module. */ @@ -122,7 +121,7 @@ declare namespace jest { /** * Returns whether the given function is a mock function. */ - function isMockFunction(fn: any): fn is Mock; + function isMockFunction(fn: any): fn is Mock; /** * Mocks a module with an auto-mocked version when it is being required. */ @@ -198,7 +197,9 @@ declare namespace jest { * spy.mockRestore(); * }); */ - function spyOn(object: T, method: M, accessType?: 'get' | 'set'): SpyInstance; + function spyOn(object: T, method: M, accessType: 'get'): SpyInstance; + function spyOn(object: T, method: M, accessType: 'set'): SpyInstance; + function spyOn(object: T, method: M): T[M] extends (...args: any[]) => any ? SpyInstance, ArgsType> : never; /** * Indicates that the module system should never return a mocked version of * the specified module from require() (e.g. that it should always return the real module). @@ -762,12 +763,12 @@ declare namespace jest { new (...args: any[]): any; } - interface Mock extends Function, MockInstance { - new (...args: any[]): T; - (...args: any[]): any; + interface Mock extends Function, MockInstance { + new (...args: Y): T; + (...args: Y): T; } - interface SpyInstance extends MockInstance {} + interface SpyInstance extends MockInstance {} /** * Wrap module with mock definitions @@ -781,14 +782,14 @@ declare namespace jest { * myApi.myApiMethod.mockImplementation(() => "test"); */ type Mocked = { - [P in keyof T]: T[P] & MockInstance; + [P in keyof T]: T[P] & MockInstance>; } & T; - interface MockInstance { + interface MockInstance { /** Returns the mock name string set by calling `mockFn.mockName(value)`. */ getMockName(): string; /** Provides access to the mock's metadata */ - mock: MockContext; + mock: MockContext; /** * Resets all information stored in the mockFn.mock.calls and mockFn.mock.instances arrays. * @@ -828,7 +829,7 @@ declare namespace jest { * * Note: `jest.fn(implementation)` is a shorthand for `jest.fn().mockImplementation(implementation)`. */ - mockImplementation(fn?: (...args: any[]) => any): Mock; + mockImplementation(fn?: (...args: Y) => T): Mock; /** * Accepts a function that will be used as an implementation of the mock for one call to the mocked function. * Can be chained so that multiple function calls produce different results. @@ -844,9 +845,9 @@ declare namespace jest { * * myMockFn((err, val) => console.log(val)); // false */ - mockImplementationOnce(fn: (...args: any[]) => any): Mock; + mockImplementationOnce(fn: (...args: Y) => T): Mock; /** Sets the name of the mock`. */ - mockName(name: string): Mock; + mockName(name: string): Mock; /** * Just a simple sugar function for: * @@ -856,7 +857,7 @@ declare namespace jest { * return this; * }); */ - mockReturnThis(): Mock; + mockReturnThis(): Mock; /** * Accepts a value that will be returned whenever the mock function is called. * @@ -868,7 +869,7 @@ declare namespace jest { * mock.mockReturnValue(43); * mock(); // 43 */ - mockReturnValue(value: any): Mock; + mockReturnValue(value: T): Mock; /** * Accepts a value that will be returned for one call to the mock function. Can be chained so that * successive calls to the mock function return different values. When there are no more @@ -885,11 +886,11 @@ declare namespace jest { * console.log(myMockFn(), myMockFn(), myMockFn(), myMockFn()); * */ - mockReturnValueOnce(value: any): Mock; + mockReturnValueOnce(value: T): Mock; /** * Simple sugar function for: `jest.fn().mockImplementation(() => Promise.resolve(value));` */ - mockResolvedValue(value: any): Mock; + mockResolvedValue(value: T | PromiseLike): Mock, Y>; /** * Simple sugar function for: `jest.fn().mockImplementationOnce(() => Promise.resolve(value));` * @@ -909,7 +910,7 @@ declare namespace jest { * }); * */ - mockResolvedValueOnce(value: any): Mock; + mockResolvedValueOnce(value: T | PromiseLike): Mock, Y>; /** * Simple sugar function for: `jest.fn().mockImplementation(() => Promise.reject(value));` * @@ -921,7 +922,7 @@ declare namespace jest { * await asyncMock(); // throws "Async error" * }); */ - mockRejectedValue(value: any): Mock; + mockRejectedValue(value: any): Mock, Y>; /** * Simple sugar function for: `jest.fn().mockImplementationOnce(() => Promise.reject(value));` @@ -939,26 +940,22 @@ declare namespace jest { * }); * */ - mockRejectedValueOnce(value: any): Mock; + mockRejectedValueOnce(value: any): Mock, Y>; } /** * Represents the result of a single call to a mock function. */ interface MockResult { + type: 'return' | 'throw' | 'incomplete'; /** - * True if the function threw. - * False if the function returned. - */ - isThrow: boolean; - /** - * The value that was either thrown or returned by the function. + * The value that was either thrown or returned by the function, or undefined if type = 'incomplete' */ value: any; } - interface MockContext { - calls: any[][]; + interface MockContext { + calls: Y[]; instances: T[]; invocationCallOrder: number[]; /** diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index de1ba90456..b724e5a256 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -253,12 +253,25 @@ jest /* Mocks and spies */ -const mock1: jest.Mock = jest.fn(); -const mock2: jest.Mock = jest.fn(() => undefined); -const mock3: jest.Mock = jest.fn(() => "abc"); -const mock4: jest.Mock<"abc"> = jest.fn((): "abc" => "abc"); -const mock5: jest.Mock = jest.fn((...args: string[]) => args.join("")); -const mock6: jest.Mock = jest.fn((arg: {}) => arg); +// $ExpectType Mock<{}, any[]> +const mock1 = jest.fn(); +// $ExpectType Mock +const mock2 = jest.fn(() => undefined); +// $ExpectType Mock +const mock3 = jest.fn(() => "abc"); +// $ExpectType Mock<"abc", []> +const mock4 = jest.fn((): "abc" => "abc"); +// $ExpectType Mock +const mock5 = jest.fn((...args: string[]) => args.join("")); +// $ExpectType Mock<{}, [{}]> +const mock6 = jest.fn((arg: {}) => arg); +// $ExpectType Mock +const mock7 = jest.fn((arg: number) => arg); + +// $ExpectError +mock7('abc'); +// $ExpectError +mock7.mockImplementation((arg: string) => 1); const genMockModule1: {} = jest.genMockFromModule("moduleName"); const genMockModule2: { a: "b" } = jest.genMockFromModule<{ a: "b" }>("moduleName"); @@ -272,8 +285,8 @@ if (jest.isMockFunction(maybeMock)) { } const mockName: string = jest.fn().getMockName(); -const mockContextVoid: jest.MockContext = jest.fn().mock; -const mockContextString: jest.MockContext = jest.fn(() => "").mock; +const mockContextVoid = jest.fn().mock; +const mockContextString = jest.fn(() => "").mock; jest.fn().mockClear(); @@ -288,9 +301,20 @@ const spiedTarget = { } }; +class SpiedTargetClass { + private _value = 3; + get value() { + return this._value; + } + set value(value) { + this._value = value; + } +} +const spiedTarget2 = new SpiedTargetClass(); + const spy1 = jest.spyOn(spiedTarget, "returnsVoid"); const spy2 = jest.spyOn(spiedTarget, "returnsVoid", "get"); -const spy3 = jest.spyOn(spiedTarget, "returnsString", "set"); +const spy3 = jest.spyOn(spiedTarget, "returnsString"); const spy1Name: string = spy1.getMockName(); const spy2Calls: any[][] = spy2.mock.calls; @@ -298,9 +322,10 @@ const spy2Calls: any[][] = spy2.mock.calls; spy2.mockClear(); spy2.mockReset(); -const spy3Mock: jest.Mock<() => string> = spy3 +const spy3Mock = spy3 .mockImplementation(() => "") .mockImplementation() + // $ExpectError .mockImplementation((arg: {}) => arg) .mockImplementation((...args: string[]) => args.join("")) .mockImplementationOnce(() => "") @@ -313,11 +338,18 @@ const spy3Mock: jest.Mock<() => string> = spy3 .mockRejectedValue("value") .mockRejectedValueOnce("value"); -let spy4: jest.SpyInstance; - +let spy4; spy4 = jest.spyOn(spiedTarget, "returnsString"); spy4.mockRestore(); +// $ExpectType SpyInstance +const spy5 = jest.spyOn(spiedTarget2, "value", "get"); +// $ExpectError +spy5.mockReturnValue('5'); + +// $ExpectType SpyInstance +const spy6 = jest.spyOn(spiedTarget2, "value", "set"); + /* Snapshot serialization */ const snapshotSerializerPlugin: jest.SnapshotSerializerPlugin = { diff --git a/types/jest/tsconfig.json b/types/jest/tsconfig.json index 8a02004840..20bc02a53b 100644 --- a/types/jest/tsconfig.json +++ b/types/jest/tsconfig.json @@ -13,6 +13,7 @@ "typeRoots": [ "../" ], + "target": "es5", "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/storybook__addon-storyshots/index.d.ts b/types/storybook__addon-storyshots/index.d.ts index dc1a2c5953..9b0517cb9f 100644 --- a/types/storybook__addon-storyshots/index.d.ts +++ b/types/storybook__addon-storyshots/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/storybooks/storybook/tree/master/addons/storyshots // Definitions by: Bradley Ayers // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.0 import * as React from 'react'; import { StoryObject } from '@storybook/react'; From 3fdb22ed85a782ed5df52f1bfd0a92a6e38784c7 Mon Sep 17 00:00:00 2001 From: antoinebrault Date: Wed, 5 Dec 2018 21:28:24 -0500 Subject: [PATCH 0013/1015] revert MockResult definition --- types/jest/index.d.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index f303230f76..02b6cb5cba 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -947,9 +947,13 @@ declare namespace jest { * Represents the result of a single call to a mock function. */ interface MockResult { - type: 'return' | 'throw' | 'incomplete'; /** - * The value that was either thrown or returned by the function, or undefined if type = 'incomplete' + * True if the function threw. + * False if the function returned. + */ + isThrow: boolean; + /** + * The value that was either thrown or returned by the function. */ value: any; } From 04ccb520cfb171db238cc890462662a4308f97bc Mon Sep 17 00:00:00 2001 From: nicky g Date: Thu, 6 Dec 2018 18:21:00 +0100 Subject: [PATCH 0014/1015] added chrome.enterprise.deviceAttributes: getDeviceSerialNumber, getDeviceAssetId, getDeviceAnnotatedLocation (with comments based on @types/chrome-apps) --- types/chrome/index.d.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/types/chrome/index.d.ts b/types/chrome/index.d.ts index ba074550f8..c8e026c719 100644 --- a/types/chrome/index.d.ts +++ b/types/chrome/index.d.ts @@ -2344,6 +2344,36 @@ declare namespace chrome.enterprise.deviceAttributes { * function(string deviceId) {...}; */ export function getDirectoryDeviceId(callback: (deviceId: string) => void): void; + /** + * @since Chrome 66. + * @description + * Fetches the device's serial number. + * Please note the purpose of this API is to administrate the device + * (e.g. generating Certificate Sign Requests for device-wide certificates). + * This API may not be used for tracking devices without the consent of the device's administrator. + * If the current user is not affiliated, returns an empty string. + * @export + * @param callback Called with the serial number of the device. + */ + export function getDeviceSerialNumber(callback: (serialNumber: string) => void): void; + /** + * @since Chrome 66. + * @description + * Fetches the administrator-annotated Asset Id. + * If the current user is not affiliated or no Asset Id has been set by the administrator, returns an empty string. + * @export + * @param callback Called with the Asset ID of the device. + */ + export function getDeviceAssetId(callback: (assetId: string) => void): void; + /** + * @since Chrome 66. + * @description + * Fetches the administrator-annotated Location. + * If the current user is not affiliated or no Annotated Location has been set by the administrator, returns an empty string. + * @export + * @param callback Called with the Annotated Location of the device. + */ + export function getDeviceAnnotatedLocation(callback: (annotatedLocation: string) => void): void; } //////////////////// From b33741070dc30e137ad563a68694a9956eeb233b Mon Sep 17 00:00:00 2001 From: antoinebrault Date: Fri, 7 Dec 2018 00:10:10 -0500 Subject: [PATCH 0015/1015] add mockImplementation optional arguments example --- types/jest/jest-tests.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index b724e5a256..b616daaeba 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -273,6 +273,10 @@ mock7('abc'); // $ExpectError mock7.mockImplementation((arg: string) => 1); +const mock8 = jest.fn((a: number, _b: string, _c: {}, _iReallyDontCare: [], _makeItStop: boolean) => Promise.resolve(_makeItStop)); +// mockImplementation not required to declare all arguments +mock8.mockImplementation((a: number) => Promise.resolve(a === 0)); + const genMockModule1: {} = jest.genMockFromModule("moduleName"); const genMockModule2: { a: "b" } = jest.genMockFromModule<{ a: "b" }>("moduleName"); From 1589af648cbc1aaab218efda364992d9f4b4b0ee Mon Sep 17 00:00:00 2001 From: nicky g Date: Fri, 7 Dec 2018 08:57:08 +0100 Subject: [PATCH 0016/1015] Added contributor --- types/chrome/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chrome/index.d.ts b/types/chrome/index.d.ts index c8e026c719..d92e6d06ac 100644 --- a/types/chrome/index.d.ts +++ b/types/chrome/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for Chrome extension development // Project: http://developer.chrome.com/extensions/ -// Definitions by: Matthew Kimber , otiai10 , couven92 , RReverser , sreimer15 +// Definitions by: Matthew Kimber , otiai10 , couven92 , RReverser , sreimer15 , ekinsol // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 From 3236add57d42a007dd994bf2fe5fd56abff06bfd Mon Sep 17 00:00:00 2001 From: Antoine Brault Date: Mon, 10 Dec 2018 10:28:16 -0500 Subject: [PATCH 0017/1015] rollback default values --- types/jest-when/index.d.ts | 2 +- types/jest/index.d.ts | 6 +++--- types/jest/jest-tests.ts | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/types/jest-when/index.d.ts b/types/jest-when/index.d.ts index fbd938b5ff..c76fdd1a9b 100644 --- a/types/jest-when/index.d.ts +++ b/types/jest-when/index.d.ts @@ -9,7 +9,7 @@ export type PartialMockInstance = Pick, 'mockReturnValue' | 'mockReturnValueOnce' | 'mockResolvedValue' | 'mockResolvedValueOnce' | 'mockRejectedValue' | 'mockRejectedValueOnce'>; -export interface When { +export interface When { (fn: jest.Mock): When; calledWith(...matchers: Y): PartialMockInstance; expectCalledWith(...matchers: Y): PartialMockInstance; diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 02b6cb5cba..b7486db0ac 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -121,7 +121,7 @@ declare namespace jest { /** * Returns whether the given function is a mock function. */ - function isMockFunction(fn: any): fn is Mock; + function isMockFunction(fn: any): fn is Mock; /** * Mocks a module with an auto-mocked version when it is being required. */ @@ -763,12 +763,12 @@ declare namespace jest { new (...args: any[]): any; } - interface Mock extends Function, MockInstance { + interface Mock extends Function, MockInstance { new (...args: Y): T; (...args: Y): T; } - interface SpyInstance extends MockInstance {} + interface SpyInstance extends MockInstance {} /** * Wrap module with mock definitions diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index b616daaeba..9054bddfa4 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -267,15 +267,20 @@ const mock5 = jest.fn((...args: string[]) => args.join("")); const mock6 = jest.fn((arg: {}) => arg); // $ExpectType Mock const mock7 = jest.fn((arg: number) => arg); +// $ExpectType Mock +const mock8: jest.Mock = jest.fn((arg: number) => arg); // $ExpectError mock7('abc'); // $ExpectError mock7.mockImplementation((arg: string) => 1); +// compiles because mock8 is declared as jest.Mock<{}, any> +mock8('abc'); +mock8.mockImplementation((arg: string) => 1); -const mock8 = jest.fn((a: number, _b: string, _c: {}, _iReallyDontCare: [], _makeItStop: boolean) => Promise.resolve(_makeItStop)); +const mock9 = jest.fn((a: number, _b: string, _c: {}, _iReallyDontCare: [], _makeItStop: boolean) => Promise.resolve(_makeItStop)); // mockImplementation not required to declare all arguments -mock8.mockImplementation((a: number) => Promise.resolve(a === 0)); +mock9.mockImplementation((a: number) => Promise.resolve(a === 0)); const genMockModule1: {} = jest.genMockFromModule("moduleName"); const genMockModule2: { a: "b" } = jest.genMockFromModule<{ a: "b" }>("moduleName"); @@ -342,8 +347,10 @@ const spy3Mock = spy3 .mockRejectedValue("value") .mockRejectedValueOnce("value"); -let spy4; +let spy4: jest.SpyInstance; spy4 = jest.spyOn(spiedTarget, "returnsString"); +// compiles because spy4 is declared as jest.SpyInstance<{}, any> +spy4.mockImplementation(() => 1); spy4.mockRestore(); // $ExpectType SpyInstance From fd0775200e5b709ff3abdb875aa958c2684a791e Mon Sep 17 00:00:00 2001 From: Antoine Brault Date: Tue, 11 Dec 2018 14:21:36 -0500 Subject: [PATCH 0018/1015] use any instead of {} for mock return type --- types/jest/index.d.ts | 4 ++-- types/jest/jest-tests.ts | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index b7486db0ac..89979493b7 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -763,12 +763,12 @@ declare namespace jest { new (...args: any[]): any; } - interface Mock extends Function, MockInstance { + interface Mock extends Function, MockInstance { new (...args: Y): T; (...args: Y): T; } - interface SpyInstance extends MockInstance {} + interface SpyInstance extends MockInstance {} /** * Wrap module with mock definitions diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index 9054bddfa4..0b7b2c21d9 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -305,6 +305,9 @@ jest.fn().mockRestore(); const spiedTarget = { returnsVoid(): void { }, + setValue(value: string): void { + this.value = value; + }, returnsString(): string { return ""; } @@ -361,6 +364,9 @@ spy5.mockReturnValue('5'); // $ExpectType SpyInstance const spy6 = jest.spyOn(spiedTarget2, "value", "set"); +let spy7: jest.SpyInstance; +spy7 = jest.spyOn(spiedTarget, "setValue"); + /* Snapshot serialization */ const snapshotSerializerPlugin: jest.SnapshotSerializerPlugin = { From 071e96b9848f04f10b5cb3d8af0a7655e2718e1c Mon Sep 17 00:00:00 2001 From: nicky g Date: Wed, 12 Dec 2018 16:38:04 +0100 Subject: [PATCH 0019/1015] - added custom types (based on chrome-apps) used in chrome.system.display under the chrome namespace - added missing chrome.system.display api calls --- types/chrome/index.d.ts | 500 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 495 insertions(+), 5 deletions(-) diff --git a/types/chrome/index.d.ts b/types/chrome/index.d.ts index d92e6d06ac..0a7e14529f 100644 --- a/types/chrome/index.d.ts +++ b/types/chrome/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for Chrome extension development // Project: http://developer.chrome.com/extensions/ -// Definitions by: Matthew Kimber , otiai10 , couven92 , RReverser , sreimer15 , ekinsol +// Definitions by: Matthew Kimber , otiai10 , couven92 , RReverser , sreimer15 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -13,6 +13,25 @@ interface Window { chrome: typeof chrome; } +declare namespace chrome { + // #region internal + ////////////// + // INTERNAL // + ////////////// + + /** + * Convert constant and variables that function as enums to string literals. + * Makes it possible to use both the enum and string. + * String enums are a combination of 'enum type' and string literal type. + */ + export type IDict = F; + export type ToStringLiteral< + C extends Object, + K = keyof C, + V = K extends keyof C ? Exclude : never> = IDict; + // #endregion internal +} + //////////////////// // Accessibility Features //////////////////// @@ -2352,16 +2371,14 @@ declare namespace chrome.enterprise.deviceAttributes { * (e.g. generating Certificate Sign Requests for device-wide certificates). * This API may not be used for tracking devices without the consent of the device's administrator. * If the current user is not affiliated, returns an empty string. - * @export * @param callback Called with the serial number of the device. */ export function getDeviceSerialNumber(callback: (serialNumber: string) => void): void; - /** + /** * @since Chrome 66. * @description * Fetches the administrator-annotated Asset Id. * If the current user is not affiliated or no Asset Id has been set by the administrator, returns an empty string. - * @export * @param callback Called with the Asset ID of the device. */ export function getDeviceAssetId(callback: (assetId: string) => void): void; @@ -2370,7 +2387,6 @@ declare namespace chrome.enterprise.deviceAttributes { * @description * Fetches the administrator-annotated Location. * If the current user is not affiliated or no Annotated Location has been set by the administrator, returns an empty string. - * @export * @param callback Called with the Annotated Location of the device. */ export function getDeviceAnnotatedLocation(callback: (annotatedLocation: string) => void): void; @@ -5877,6 +5893,480 @@ declare namespace chrome.system.storage { export var onDetached: SystemStorageDetachedEvent; } +//////////////////// +// System Display // +//////////////////// +/** + * Use the system.display API to query display metadata. + * Permissions: 'system.display' + * @since Chrome 30. + */ +declare namespace chrome.system.display { + + export const DisplayPosition: { + TOP: 'top', + RIGHT: 'right', + BOTTOM: 'bottom', + LEFT: 'left' + }; + export const MirrorMode: { + OFF: 'off', + NORMAL: 'normal', + MIXED: 'mixed' + }; + export interface Bounds { + /** The x-coordinate of the upper-left corner. */ + left: number; + /** The y-coordinate of the upper-left corner. */ + top: number; + /** The width of the display in pixels. */ + width: number; + /** The height of the display in pixels. */ + height: number; + } + + export interface Insets { + /** The x-axis distance from the left bound. */ + left: number; + /** The y-axis distance from the top bound. */ + top: number; + /** The x-axis distance from the right bound. */ + right: number; + /** The y-axis distance from the bottom bound. */ + bottom: number; + } + + /** + * @since Chrome 57 + */ + export interface Point { + /** The x-coordinate of the point. */ + x: number; + /** The y-coordinate of the point. */ + y: number; + } + + /** + * @since Chrome 57 + */ + export interface TouchCalibrationPair { + /** The coordinates of the display point. */ + displayPoint: Point; + /** The coordinates of the touch point corresponding to the display point. */ + touchPoint: Point; + } + + /** + * @since Chrome 52 + */ + export interface DisplayMode { + /** The display mode width in device independent (user visible) pixels. */ + width: number; + + /** The display mode height in device independent (user visible) pixels. */ + height: number; + + /** The display mode width in native pixels. */ + widthInNativePixels: number; + + /** The display mode height in native pixels. */ + heightInNativePixels: number; + + /** + * @deprecated Deprecated since Chrome 70. Use `displayZoomFactor` + * @description The display mode UI scale factor. + **/ + uiScale: number; + + /** The display mode device scale factor. */ + deviceScaleFactor: number; + + /** + * The display mode refresh rate in hertz. + * @since Chrome 67 + */ + refreshRate: number; + + /** True if the mode is the display's native mode. */ + isNative: boolean; + + /** True if the display mode is currently selected. */ + isSelected: boolean; + } + + /** + * @since Chrome 53 + */ + export interface DisplayLayout { + + /** The unique identifier of the display. */ + id: string; + /** The unique identifier of the parent display. Empty if this is the root. */ + parentId: string; + /** + * The layout position of this display relative to the parent. + * This will be ignored for the root. + * @see enum + */ + position: ToStringLiteral; + /** The offset of the display along the connected edge. 0 indicates that the topmost or leftmost corners are aligned. */ + offset: number; + } + + /** + * The pairs of point used to calibrate the display. + */ + export interface TouchCalibrationPairs { + /** First pair of touch and display point required for touch calibration. */ + pair1: TouchCalibrationPair, + /** Second pair of touch and display point required for touch calibration. */ + pair2: TouchCalibrationPair, + /** Third pair of touch and display point required for touch calibration. */ + pair3: TouchCalibrationPair, + /** Fourth pair of touch and display point required for touch calibration. */ + pair4: TouchCalibrationPair + } + + /** + * Representation of info data to be used in chrome.system.display.setDisplayProperties() + */ + export interface DisplayPropertiesInfo { + /** + * @requires(CrOS) Chrome OS only. + * @description + * If set to true, changes the display mode to unified desktop. + * If set to false, unified desktop mode will be disabled. + * This is only valid for the primary display. + * If provided, mirroringSourceId must not be provided and other properties may not apply. + * This is has no effect if not provided. + * @see(See `enableUnifiedDesktop` for details). + * @since Chrome 59 + * */ + isUnified?: boolean; + + /** + * @requires(CrOS) Chrome OS only. + * @deprecated Deprecated since Chrome 68. Use ´setMirrorMode´ + * @see setMirrorMode + * @description + * If set and not empty, enables mirroring for this display. + * Otherwise disables mirroring for this display. + * This value should indicate the id of the source display to mirror, + * which must not be the same as the id passed to setDisplayProperties. + * If set, no other property may be set. + */ + mirroringSourceId?: string; + + /** + * If set to true, makes the display primary. + * No-op if set to false. + */ + isPrimary?: boolean; + + /** + * If set, sets the display's overscan insets to the provided values. + * Note that overscan values may not be negative or larger than a half of the screen's size. + * Overscan cannot be changed on the internal monitor. It's applied after isPrimary parameter. + */ + overscan?: Insets; + + /** + * If set, updates the display's rotation. + * Legal values are [0, 90, 180, 270]. + * The rotation is set clockwise, relative to the display's vertical position. + * It's applied after overscan parameter. + */ + rotation?: 0 | 90 | 180 | 270; + + /** + * If set, updates the display's logical bounds origin along x-axis. + * Applied together with boundsOriginY, if boundsOriginY is set. + * Note that, when updating the display origin, some constraints will be applied, + * so the final bounds origin may be different than the one set. + * The final bounds can be retrieved using getInfo. The bounds origin is applied + * after rotation. The bounds origin cannot be changed on the primary display. + * Note that is also invalid to set bounds origin values if isPrimary is also set + * (as isPrimary parameter is applied first). + */ + boundsOriginX?: number; + + /** + * If set, updates the display's logical bounds origin along y-axis. + * @see[See documentation for boundsOriginX parameter.] + */ + boundsOriginY: number; + + /** + * If set, updates the display mode to the mode matching this value. + * @since Chrome 52 + */ + displayMode?: DisplayMode; + + /** + * @since Chrome 65. + * @description + * If set, updates the zoom associated with the display. + * This zoom performs re-layout and repaint thus resulting + * in a better quality zoom than just performing + * a pixel by pixel stretch enlargement. + */ + displayZoomFactor?: number; + } + + /** + * Options affecting how the information is returned. + * @since Chrome 59 + */ + export interface DisplayInfoFlags { + /** + * If set to true, only a single DisplayUnitInfo will be returned by getInfo when in unified desktop mode. + * @see[enableUnifiedDesktop] + * @default false + */ + singleUnified?: boolean; + } + + /** Information about display properties. */ + export interface DisplayInfo { + /** The unique identifier of the display. */ + id: string; + /** The user-friendly name (e.g. 'HP LCD monitor'). */ + name: string; + /** + * @requires(CrOS Kiosk app) Only available in Chrome OS Kiosk apps + */ + edid?: { + /** + * 3 character manufacturer code. + */ + manufacturerId: string; + /** + * 2 byte manufacturer-assigned code. + */ + productId: string; + /** + * Year of manufacturer. + */ + yearOfManufacture?: string; + } + /** + * @requires(CrOS) Only working properly on Chrome OS. + * Identifier of the display that is being mirrored on the display unit. + * If mirroring is not in progress, set to an empty string + * Currently exposed only on ChromeOS. + * Will be empty string on other platforms. + */ + mirroringSourceId: string; + /** + * @requires(CrOS) Only available on Chrome OS. + * Identifiers of the displays to which the source display is being mirrored. + * Empty if no displays are being mirrored. This will be set to the same value + * for all displays. + * ❗ This must not include *mirroringSourceId*. ❗ + */ + mirroringDestinationIds: string[]; + /** True if this is the primary display. */ + isPrimary: boolean; + /** True if this is an internal display. */ + isInternal: boolean; + /** True if this display is enabled. */ + isEnabled: boolean; + /** The number of pixels per inch along the x-axis. */ + dpiX: number; + /** The number of pixels per inch along the y-axis. */ + dpiY: number; + /** The display's clockwise rotation in degrees relative to the vertical position. Currently exposed only on ChromeOS. Will be set to 0 on other platforms. */ + rotation: number; + /** The display's logical bounds. */ + bounds: Bounds; + /** The display's insets within its screen's bounds. Currently exposed only on ChromeOS. Will be set to empty insets on other platforms. */ + overscan: Insets; + /** The usable work area of the display within the display bounds. The work area excludes areas of the display reserved for OS, for example taskbar and launcher. */ + workArea: Bounds; + /** + * @requires(CrOS) Only available on Chrome OS. + * The list of available display modes. + * The current mode will have isSelected=true. + * Only available on Chrome OS. + * Will be set to an empty array on other platforms. + */ + modes: DisplayMode[]; + /** True if this display has a touch input device associated with it. */ + hasTouchSupport: boolean; + /** A list of zoom factor values that can be set for the display. */ + availableDisplayZoomFactors: number[]; + /** + * The ratio between the display's current and default zoom. + * For example, value 1 is equivalent to 100% zoom, and value 1.5 is equivalent to 150% zoom. + * */ + displayZoomFactor: number; + } + + export interface MirrorModeInfo { + /** + * The mirror mode that should be set. + * **off** + * Use the default mode (extended or unified desktop). + * **normal** + * The default source display will be mirrored to all other displays. + * **mixed** + * The specified source display will be mirrored to the provided destination displays. All other connected displays will be extended. + */ + mode?: 'off' | 'normal' | 'mixed'; + } + export interface MirrorModeInfoMixed extends MirrorModeInfo { + mode: 'mixed'; + mirroringSourceId?: string; + /** The ids of the mirroring destination displays. */ + mirroringDestinationIds?: string[]; + } + + /** + * Requests the information for all attached display devices. + * @param callback The callback to invoke with the results. + */ + function getInfo(callback: (info: DisplayInfo[]) => void): void; + /** + * Requests the information for all attached display devices. + * @since Chrome 59 + * @param flags Options affecting how the information is returned. + * @param callback The callback to invoke with the results. + */ + function getInfo(flags: DisplayInfoFlags, callback: (info: DisplayInfo[]) => void): void; + + /** + * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. + * @description Requests the layout info for all displays. + * @since Chrome 53 + * @export + * @param callback The callback to invoke with the results. + */ + function getDisplayLayout(callback: (layouts: DisplayLayout[]) => void): void; + + /** + * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. + * @description + * Updates the properties for the display specified by **id**, + * according to the information provided in **info**. + * On failure, runtime.lastError will be set. + * @param {string} id The display's unique identifier. + * @param {DisplayPropertiesInfo} info The information about display properties that should be changed. A property will be changed only if a new value for it is specified in |info|. + * @param {() => void} [callback] Empty function called when the function finishes. To find out whether the function succeeded, runtime.lastError should be queried. + */ + function setDisplayProperties(id: string, info: DisplayPropertiesInfo, callback?: () => void): void; + + /** + * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. + * @description + * Set the layout for all displays. + * Any display not included will use the default layout. + * If a layout would overlap or be otherwise invalid it will be adjusted to a valid layout. + * After layout is resolved, an onDisplayChanged event will be triggered. + * @since Chrome 53 + * @param layouts The layout information, required for all displays except the primary display. + * @param callback Empty function called when the function finishes. To find out whether the function succeeded, runtime.lastError should be queried. + */ + function setDisplayLayout(layouts: DisplayLayout[], callback?: () => void): void; + + /** + * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. + * @description + * Enables/disables the unified desktop feature. + * Note that this simply enables the feature, but will not change the actual desktop mode. + * (That is, if the desktop is in mirror mode, it will stay in mirror mode) + * @since Chrome 46 + * @param {boolean} enabled True if unified desktop should be enabled. + */ + function enableUnifiedDesktop(enabled: boolean): void; + /** + * Starts overscan calibration for a display. + * This will show an overlay on the screen indicating the current overscan insets. + * If overscan calibration for display **id** is in progress this will reset calibration. + * @since Chrome 53 + * @param id The display's unique identifier. + */ + function overscanCalibrationStart(id: string): void; + /** + * Adjusts the current overscan insets for a display. + * Typically this should etiher move the display along an axis (e.g. left+right have the same value) + * or scale it along an axis (e.g. top+bottom have opposite values). + * Each Adjust call is cumulative with previous calls since Start. + * @since Chrome 53 + * @param id The display's unique identifier. + * @param delta The amount to change the overscan insets. + */ + function overscanCalibrationAdjust(id: string, delta: Insets): void; + + /** + * Resets the overscan insets for a display to the last saved value (i.e before Start was called). + * @since Chrome 53 + * @param id The display's unique identifier. + */ + function overscanCalibrationReset(id: string): void; + + /** + * Complete overscan adjustments for a display by saving the current values and hiding the overlay. + * @since Chrome 53 + * @param id The display's unique identifier. + */ + function overscanCalibrationComplete(id: string): void; + + /** + * Displays the native touch calibration UX for the display with **id** as display id. + * This will show an overlay on the screen with required instructions on how to proceed. + * The callback will be invoked in case of successful calibraion only. + * If the calibration fails, this will throw an error. + * @since Chrome 57 + * @param id The display's unique identifier. + * @param callback Optional callback to inform the caller that the touch calibration has ended. The argument of the callback informs if the calibration was a success or not. + */ + function showNativeTouchCalibration(id: string, callback: (success: boolean) => void): void; + + /** + * Starts custom touch calibration for a display. + * This should be called when using a custom UX for collecting calibration data. + * If another touch calibration is already in progress this will throw an error. + * @since Chrome 57 + * @param id The display's unique identifier. + */ + function startCustomTouchCalibration(id: string): void; + + /** + * Sets the touch calibration pairs for a display. + * These **pairs** would be used to calibrate the touch screen for display with **id** called in startCustomTouchCalibration(). + * Always call **startCustomTouchCalibration** before calling this method. + * If another touch calibration is already in progress this will throw an error. + * @since Chrome 57 + * @param pairs The pairs of point used to calibrate the display. + * @param bounds Bounds of the display when the touch calibration was performed. |bounds.left| and |bounds.top| values are ignored. + * @throws Error + */ + function completeCustomTouchCalibration(pairs: TouchCalibrationPairs, bounds: Bounds): void; + + /** + * Resets the touch calibration for the display and brings it back to its default state by clearing any touch calibration data associated with the display. + * @since Chrome 57 + * @param id The display's unique identifier. + */ + function clearTouchCalibration(id: string): void; + + /** + * @requires(CrOS Kiosk app) Chrome OS Kiosk apps only + * @since Chrome 65. + * @description + * Sets the display mode to the specified mirror mode. + * Each call resets the state from previous calls. + * Calling setDisplayProperties() will fail for the + * mirroring destination displays. + */ + function setMirrorMode(info: MirrorModeInfo | MirrorModeInfoMixed, callback: () => void): void; + + /** + * Fired when anything changes to the display configuration. + */ + const onDisplayChanged: chrome.events.Event<() => void>; +} + //////////////////// // TabCapture //////////////////// From a0c18d13b6ff82a9c922a7908140f60eaa6cc023 Mon Sep 17 00:00:00 2001 From: nicky g Date: Wed, 12 Dec 2018 16:49:44 +0100 Subject: [PATCH 0020/1015] added missing exports in system.chrome.display --- types/chrome/index.d.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/types/chrome/index.d.ts b/types/chrome/index.d.ts index 0a7e14529f..9e324fa060 100644 --- a/types/chrome/index.d.ts +++ b/types/chrome/index.d.ts @@ -6225,14 +6225,14 @@ declare namespace chrome.system.display { * Requests the information for all attached display devices. * @param callback The callback to invoke with the results. */ - function getInfo(callback: (info: DisplayInfo[]) => void): void; + export function getInfo(callback: (info: DisplayInfo[]) => void): void; /** * Requests the information for all attached display devices. * @since Chrome 59 * @param flags Options affecting how the information is returned. * @param callback The callback to invoke with the results. */ - function getInfo(flags: DisplayInfoFlags, callback: (info: DisplayInfo[]) => void): void; + export function getInfo(flags: DisplayInfoFlags, callback: (info: DisplayInfo[]) => void): void; /** * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. @@ -6241,7 +6241,7 @@ declare namespace chrome.system.display { * @export * @param callback The callback to invoke with the results. */ - function getDisplayLayout(callback: (layouts: DisplayLayout[]) => void): void; + export function getDisplayLayout(callback: (layouts: DisplayLayout[]) => void): void; /** * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. @@ -6253,7 +6253,7 @@ declare namespace chrome.system.display { * @param {DisplayPropertiesInfo} info The information about display properties that should be changed. A property will be changed only if a new value for it is specified in |info|. * @param {() => void} [callback] Empty function called when the function finishes. To find out whether the function succeeded, runtime.lastError should be queried. */ - function setDisplayProperties(id: string, info: DisplayPropertiesInfo, callback?: () => void): void; + export function setDisplayProperties(id: string, info: DisplayPropertiesInfo, callback?: () => void): void; /** * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. @@ -6266,7 +6266,7 @@ declare namespace chrome.system.display { * @param layouts The layout information, required for all displays except the primary display. * @param callback Empty function called when the function finishes. To find out whether the function succeeded, runtime.lastError should be queried. */ - function setDisplayLayout(layouts: DisplayLayout[], callback?: () => void): void; + export function setDisplayLayout(layouts: DisplayLayout[], callback?: () => void): void; /** * @requires(CrOS Kiosk apps | WebUI) This is only available to Chrome OS Kiosk apps and Web UI. @@ -6277,7 +6277,7 @@ declare namespace chrome.system.display { * @since Chrome 46 * @param {boolean} enabled True if unified desktop should be enabled. */ - function enableUnifiedDesktop(enabled: boolean): void; + export function enableUnifiedDesktop(enabled: boolean): void; /** * Starts overscan calibration for a display. * This will show an overlay on the screen indicating the current overscan insets. @@ -6285,7 +6285,7 @@ declare namespace chrome.system.display { * @since Chrome 53 * @param id The display's unique identifier. */ - function overscanCalibrationStart(id: string): void; + export function overscanCalibrationStart(id: string): void; /** * Adjusts the current overscan insets for a display. * Typically this should etiher move the display along an axis (e.g. left+right have the same value) @@ -6295,21 +6295,21 @@ declare namespace chrome.system.display { * @param id The display's unique identifier. * @param delta The amount to change the overscan insets. */ - function overscanCalibrationAdjust(id: string, delta: Insets): void; + export function overscanCalibrationAdjust(id: string, delta: Insets): void; /** * Resets the overscan insets for a display to the last saved value (i.e before Start was called). * @since Chrome 53 * @param id The display's unique identifier. */ - function overscanCalibrationReset(id: string): void; + export function overscanCalibrationReset(id: string): void; /** * Complete overscan adjustments for a display by saving the current values and hiding the overlay. * @since Chrome 53 * @param id The display's unique identifier. */ - function overscanCalibrationComplete(id: string): void; + export function overscanCalibrationComplete(id: string): void; /** * Displays the native touch calibration UX for the display with **id** as display id. @@ -6320,7 +6320,7 @@ declare namespace chrome.system.display { * @param id The display's unique identifier. * @param callback Optional callback to inform the caller that the touch calibration has ended. The argument of the callback informs if the calibration was a success or not. */ - function showNativeTouchCalibration(id: string, callback: (success: boolean) => void): void; + export function showNativeTouchCalibration(id: string, callback: (success: boolean) => void): void; /** * Starts custom touch calibration for a display. @@ -6329,7 +6329,7 @@ declare namespace chrome.system.display { * @since Chrome 57 * @param id The display's unique identifier. */ - function startCustomTouchCalibration(id: string): void; + export function startCustomTouchCalibration(id: string): void; /** * Sets the touch calibration pairs for a display. @@ -6341,14 +6341,14 @@ declare namespace chrome.system.display { * @param bounds Bounds of the display when the touch calibration was performed. |bounds.left| and |bounds.top| values are ignored. * @throws Error */ - function completeCustomTouchCalibration(pairs: TouchCalibrationPairs, bounds: Bounds): void; + export function completeCustomTouchCalibration(pairs: TouchCalibrationPairs, bounds: Bounds): void; /** * Resets the touch calibration for the display and brings it back to its default state by clearing any touch calibration data associated with the display. * @since Chrome 57 * @param id The display's unique identifier. */ - function clearTouchCalibration(id: string): void; + export function clearTouchCalibration(id: string): void; /** * @requires(CrOS Kiosk app) Chrome OS Kiosk apps only @@ -6359,12 +6359,12 @@ declare namespace chrome.system.display { * Calling setDisplayProperties() will fail for the * mirroring destination displays. */ - function setMirrorMode(info: MirrorModeInfo | MirrorModeInfoMixed, callback: () => void): void; + export function setMirrorMode(info: MirrorModeInfo | MirrorModeInfoMixed, callback: () => void): void; /** * Fired when anything changes to the display configuration. */ - const onDisplayChanged: chrome.events.Event<() => void>; + export const onDisplayChanged: chrome.events.Event<() => void>; } //////////////////// From 795722e0dc55a6f18a278f594a12bc4ec42d8ebe Mon Sep 17 00:00:00 2001 From: Aleksandar Manukov Date: Sat, 15 Dec 2018 17:25:11 +0200 Subject: [PATCH 0021/1015] Add bootstrap-colorpicker@2.5.3 --- .../bootstrap-colorpicker@2.5.3-tests.ts | 0 types/bootstrap-colorpicker@2.5.3/index.d.ts | 267 ++++++++++++++++++ .../bootstrap-colorpicker@2.5.3/tsconfig.json | 22 ++ types/bootstrap-colorpicker@2.5.3/tslint.json | 1 + 4 files changed, 290 insertions(+) create mode 100644 types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts create mode 100644 types/bootstrap-colorpicker@2.5.3/index.d.ts create mode 100644 types/bootstrap-colorpicker@2.5.3/tsconfig.json create mode 100644 types/bootstrap-colorpicker@2.5.3/tslint.json diff --git a/types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts b/types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/types/bootstrap-colorpicker@2.5.3/index.d.ts b/types/bootstrap-colorpicker@2.5.3/index.d.ts new file mode 100644 index 0000000000..222b939b89 --- /dev/null +++ b/types/bootstrap-colorpicker@2.5.3/index.d.ts @@ -0,0 +1,267 @@ +// Type definitions for bootstrap-colorpicker 2.5.3 +// Project: https://github.com/farbelous/bootstrap-colorpicker/tree/v2.x +// Definitions by: Aleksandar Manukov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +type ColorPickerAlignOptions = 'right' | 'left'; + +type ColorPickerEvents = 'create' | + 'showPicker' | + 'hidePicker' | + 'changeColor' | + 'disable' | + 'enable' | + 'destroy' + +/** + * You can set colorpicker options either as a plugin parameter or data-* attributes + */ +interface ColorPickerOptions { + /** + * If not false, forces the color format to be hex, rgb or rgba, otherwise the format is automatically detected. + * + * Default: false + */ + format: string; + + /** + * If not false, sets the color to this value. + * + * Default: false + */ + color: string; + + /** + * If not false, the picker will be contained inside this element, otherwise it will be appended to the document body. + * + * Default: false + */ + container: string | JQuery; + + /** + * Children selector for the component or element that trigger the colorpicker and which background color will change (needs an inner element). + * + * Default: '.add-on, .input-group-addon' + */ + component: string | JQuery; + + /** + * Children selector for the input that will store the picker selected value. + * + * Default: 'input' + */ + input: string | JQuery; + + /** + * If true, put a '#' (number sign) before hex strings. + * + * Default: true + */ + hexNumberSignPrefix: boolean; + + /** + * If true, the hue and alpha channel bars will be rendered horizontally, above the saturation selector. + * + * Default: false + */ + horizontal: boolean; + + /** + * If true, forces to show the colorpicker as an inline element. + * + * Default: false + */ + inline: boolean; + + /** + * Vertical sliders configuration (read source code if you really need to tweak this). + */ + sliders: object; + + /** + * Horizontal sliders configuration (read source code if you really need to tweak this). + */ + slidersHorz: object; + + /** + * Customizes the default colorpicker HTML template. + */ + template: string; + + /** + * By default, the colorpicker is aligned to the right of the input. If you need to switch it to the left, set align to 'left'. + * + * Default: 'right' + */ + align: ColorPickerAlignOptions; + + /** + * Adds this class to the colorpicker widget. + * + * Default: null + */ + customClass: string; + + /** + * List of pre selected colors (hex format). If you choose one of these colors, the alias is returned instead of the hex code. + * + * Default: null + */ + colorSelectors: object; + + /** + * Fallback color string that will be applied when the color failed to be parsed. If null, it will keep the current color if any. + * + * Default: null + */ + fallbackColor: string; + + /** + * Fallback color format (e.g. when not specified or for alias mode, when selecting non aliased colors) + * + * Default: hex + */ + fallbackFormat: string; +} + +interface Color { + colors: {}; + fallbackFormat: string; + fallbackValue: string; + hexNumberSignPrefix: boolean; + origFormat: string; + predefinedColors: {}; + value: { + h: number; + s: number; + b: number; + a: number; + } + + /** + * Set a new color. The value is parsed and tries to do a quess on the format. + */ + setColor(value: string): void; + + /** + * Set the HUE with a value between 0 and 1. + */ + setHue(value: number): void; + + /** + * Set the saturation with a value between 0 and 1. + */ + setSaturation(value: number): void; + + /** + * Set the brightness with a value between 0 and 1. + */ + setBrightness(value: number): void; + + /** + * Set the transparency with a value between 0 and 1. + */ + setAlpha(value: number): void; + + /** + * Returns a hash with red, green, blue and alpha. + */ + toRGB(): string; + + /** + * Returns a string with HEX format for the current color. + */ + toHex(): string; + + /** + * Returns a hash with HSLA values. + */ + toHSL(): string; +} + +interface ColorPicker { + color: Color; + component: boolean; + container: boolean; + disabled: boolean; + element: JQuery; + format: string; + input: JQuery; + options: ColorPickerOptions; + picker: JQuery; +} + +interface ColorPickerEventObject { + +} + +interface JQuery { + /** + * Initializes an colorpicker. + */ + colorpicker(): JQuery; + + /** + * Initializes an colorpicker. + */ + colorpicker(options: ColorPickerOptions): JQuery; + + /** + * Gets the value from the input or the data attribute (if has no input), otherwise returns the default value, which defaults to #000000 if not specified. + */ + colorpicker(methodName: 'getValue', defaultValue: string): string; + + /** + * Set a new value for the color picker (also updates everything). Triggers 'changeColor' event. + */ + colorpicker(methodName: 'setValue', value: any): any; + + /** + * Show the color picker + */ + colorpicker(methodName: 'show'): void; + + /** + * Hide the color picker + */ + colorpicker(methodName: 'hide'): void; + + /** + * Updates the color picker's position relative to the element + */ + colorpicker(methodName: 'reposition'): void; + + /** + * Refreshes the widget colors (this is done automatically) + */ + colorpicker(methodName: 'update'): void; + + /** + * Enable the color picker. + */ + colorpicker(methodName: 'enable'): void; + + /** + * Disable the color picker. + */ + colorpicker(methodName: 'disable'): void; + + /** + * Destroys the colorpicker widget and unbind all .colorpicker events from the element and component + */ + colorpicker(methodName: 'destroy'): void; + + /** + * Access to the colorpicker API directly + */ + data(methodName: 'colorpicker'): ColorPicker; + + off(events: ColorPickerEvents, selector?: string, handler?: (event: ColorPickerEventObject) => any): JQuery; + off(events: ColorPickerEvents, handler: (event: ColorPickerEventObject) => any): JQuery; + + on(events: ColorPickerEvents, selector: string, data: any, handler?: (event: ColorPickerEventObject) => any): JQuery; + on(events: ColorPickerEvents, selector: string, handler: (event: ColorPickerEventObject) => any): JQuery; + on(events: ColorPickerEvents, handler: (event: ColorPickerEventObject) => any): JQuery; +} \ No newline at end of file diff --git a/types/bootstrap-colorpicker@2.5.3/tsconfig.json b/types/bootstrap-colorpicker@2.5.3/tsconfig.json new file mode 100644 index 0000000000..61299349f7 --- /dev/null +++ b/types/bootstrap-colorpicker@2.5.3/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", + "bootstrap-colorpicker@2.5.3-tests.ts" + ] +} diff --git a/types/bootstrap-colorpicker@2.5.3/tslint.json b/types/bootstrap-colorpicker@2.5.3/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/bootstrap-colorpicker@2.5.3/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From c8a1eeb459f2717f8482ffb2e77cba1be61dbac2 Mon Sep 17 00:00:00 2001 From: Aleksandar Manukov <34056917+aleksandar-manukov@users.noreply.github.com> Date: Sat, 15 Dec 2018 17:55:15 +0200 Subject: [PATCH 0022/1015] Rename bootstrap-colorpicker@2.5.3 to bootstrap-colorpicker@2.x --- .../bootstrap-colorpicker@2.x-tests.ts} | 0 .../index.d.ts | 0 .../tsconfig.json | 0 .../tslint.json | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename types/{bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts => bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts} (100%) rename types/{bootstrap-colorpicker@2.5.3 => bootstrap-colorpicker@2.x}/index.d.ts (100%) rename types/{bootstrap-colorpicker@2.5.3 => bootstrap-colorpicker@2.x}/tsconfig.json (100%) rename types/{bootstrap-colorpicker@2.5.3 => bootstrap-colorpicker@2.x}/tslint.json (100%) diff --git a/types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts b/types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts rename to types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts diff --git a/types/bootstrap-colorpicker@2.5.3/index.d.ts b/types/bootstrap-colorpicker@2.x/index.d.ts similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/index.d.ts rename to types/bootstrap-colorpicker@2.x/index.d.ts diff --git a/types/bootstrap-colorpicker@2.5.3/tsconfig.json b/types/bootstrap-colorpicker@2.x/tsconfig.json similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/tsconfig.json rename to types/bootstrap-colorpicker@2.x/tsconfig.json diff --git a/types/bootstrap-colorpicker@2.5.3/tslint.json b/types/bootstrap-colorpicker@2.x/tslint.json similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/tslint.json rename to types/bootstrap-colorpicker@2.x/tslint.json From bbc6a27c0394914f331dd6457f81166448e04d60 Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Wed, 19 Dec 2018 21:49:05 +0000 Subject: [PATCH 0023/1015] [@babel/traverse]: Allowed node aliases as keys in visitors. This is made possible by https://github.com/babel/babel/pull/9110. When the next version after v7.2.2 is released, the package.json can be updated and the build will no longer fail. --- types/babel__traverse/babel__traverse-tests.ts | 5 +++++ types/babel__traverse/index.d.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/types/babel__traverse/babel__traverse-tests.ts b/types/babel__traverse/babel__traverse-tests.ts index 70f8c5f0b6..98a0338021 100644 --- a/types/babel__traverse/babel__traverse-tests.ts +++ b/types/babel__traverse/babel__traverse-tests.ts @@ -150,3 +150,8 @@ const VisitorStateTest: Visitor = { } } }; + +const VisitorAliasTest: Visitor = { + Function() {}, + Expression() {}, +}; diff --git a/types/babel__traverse/index.d.ts b/types/babel__traverse/index.d.ts index 89e242129b..fe817d5daf 100644 --- a/types/babel__traverse/index.d.ts +++ b/types/babel__traverse/index.d.ts @@ -145,6 +145,8 @@ export class Binding { export type Visitor = VisitNodeObject & { [Type in Node["type"]]?: VisitNode>; +} & { + [K in keyof t.Aliases]?: VisitNode }; export type VisitNode = VisitNodeFunction | VisitNodeObject; From 0ccaf36b05c786d4f332658a9f471f0c5bd71acb Mon Sep 17 00:00:00 2001 From: antoinebrault Date: Sat, 5 Jan 2019 15:16:49 -0500 Subject: [PATCH 0024/1015] add jest-when type inference --- types/jest-when/index.d.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/types/jest-when/index.d.ts b/types/jest-when/index.d.ts index c76fdd1a9b..386911ed7c 100644 --- a/types/jest-when/index.d.ts +++ b/types/jest-when/index.d.ts @@ -6,13 +6,17 @@ /// -export type PartialMockInstance = Pick, 'mockReturnValue' | 'mockReturnValueOnce' | 'mockResolvedValue' - | 'mockResolvedValueOnce' | 'mockRejectedValue' | 'mockRejectedValueOnce'>; - -export interface When { - (fn: jest.Mock): When; - calledWith(...matchers: Y): PartialMockInstance; - expectCalledWith(...matchers: Y): PartialMockInstance; +export interface WhenMock extends jest.Mock { + calledWith(...matchers: Y): WhenMock; + expectCalledWith(...matchers: Y): WhenMock; + mockReturnValue(value: T): WhenMock; + mockReturnValueOnce(value: T): WhenMock; + mockResolvedValue(value: T | PromiseLike): WhenMock, Y>; + mockResolvedValueOnce(value: T | PromiseLike): WhenMock, Y>; + mockRejectedValue(value: T | PromiseLike): WhenMock, Y>; + mockRejectedValueOnce(value: T | PromiseLike): WhenMock, Y>; } +export type When = (fn: jest.Mock) => WhenMock; + export const when: When; From c4e76c862663d7d6646cd24068cbdc05d6161101 Mon Sep 17 00:00:00 2001 From: Nicolas Penin Date: Sun, 6 Jan 2019 19:41:15 +0100 Subject: [PATCH 0025/1015] Update index.d.ts fixed typescript compilation issue --- types/debug/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/debug/index.d.ts b/types/debug/index.d.ts index 2eca1c8fb8..a03d5cd988 100644 --- a/types/debug/index.d.ts +++ b/types/debug/index.d.ts @@ -6,7 +6,7 @@ // Brasten Sager // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var debug: debug.IDebug; +declare var debug: debug.IDebug & {debug:debug.IDebug, default:debug.IDebug}; export = debug; export as namespace debug; From 43f9cfc7f19576a637561ca27eb7e0aaa6f74125 Mon Sep 17 00:00:00 2001 From: Nicolas Penin Date: Mon, 7 Jan 2019 10:51:47 +0100 Subject: [PATCH 0026/1015] fixed coding convention --- types/debug/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/debug/index.d.ts b/types/debug/index.d.ts index a03d5cd988..e8cfac264b 100644 --- a/types/debug/index.d.ts +++ b/types/debug/index.d.ts @@ -6,7 +6,7 @@ // Brasten Sager // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var debug: debug.IDebug & {debug:debug.IDebug, default:debug.IDebug}; +declare var debug: debug.IDebug & {debug: debug.IDebug, default: debug.IDebug}; export = debug; export as namespace debug; From a57f667049a912095a0d11490ee6bcb5a5ed97af Mon Sep 17 00:00:00 2001 From: James Lawrence Date: Tue, 8 Jan 2019 23:18:16 +0000 Subject: [PATCH 0027/1015] Allow dynamic CSS values based on component props --- types/react-jss/lib/injectSheet.d.ts | 50 +++++++++++++++++----------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/types/react-jss/lib/injectSheet.d.ts b/types/react-jss/lib/injectSheet.d.ts index fd66af5c38..be3bee933b 100644 --- a/types/react-jss/lib/injectSheet.d.ts +++ b/types/react-jss/lib/injectSheet.d.ts @@ -53,26 +53,35 @@ export type PropsOf = C extends new (props: infer P) => React.Component */ export type PropInjector = < C extends React.ComponentType, InjectedProps>> ->( + >( component: C ) => React.ComponentType< Omit>, keyof InjectedProps> & - AdditionalProps ->; + AdditionalProps + >; -export interface CSSProperties extends CSS.Properties { +type cssNumberOrString = CSS.Properties + +// Allow functions that take the properties of the component and return a CSS value +export type CssRule = { + [K in keyof cssNumberOrString]: + | (cssNumberOrString[K]) + | ((props: Props) => cssNumberOrString[K]) +}[keyof CSS.Properties] + +export interface CSSProperties { // Allow pseudo selectors and media queries [k: string]: - | CSS.Properties[keyof CSS.Properties] - | CSSProperties; + | CssRule + | CSSProperties; } -export type Styles = Record< +export type Styles = Record< ClassKey, - CSSProperties ->; -export type StyleCreator = ( + CSSProperties + >; +export type StyleCreator = ( theme: T -) => Styles; +) => Styles; export interface Theming { channel: string; @@ -89,15 +98,16 @@ export interface InjectOptions extends CreateStyleSheetOptions { export type ClassNameMap = Record; export type WithSheet< S extends string | Styles | StyleCreator, - GivenTheme = undefined -> = { + GivenTheme = undefined, + Props = {} + > = { classes: ClassNameMap< S extends string ? S - : S extends StyleCreator - ? C - : S extends Styles ? C : never - >; + : S extends StyleCreator + ? C + : S extends Styles ? C : never + >; } & WithTheme ? T : GivenTheme>; export interface WithTheme { @@ -110,7 +120,7 @@ export interface StyledComponentProps { innerRef?: React.Ref | React.RefObject; } -export default function injectSheet( - stylesOrCreator: Styles | StyleCreator, +export default function injectSheet( + stylesOrCreator: Styles | StyleCreator, options?: InjectOptions -): PropInjector, StyledComponentProps>; +): PropInjector, StyledComponentProps>; From 6f2624fb38349499664984ca14893f72f9c4e461 Mon Sep 17 00:00:00 2001 From: James Lawrence Date: Tue, 8 Jan 2019 23:31:16 +0000 Subject: [PATCH 0028/1015] Add attribution, fix linter errors --- types/react-jss/index.d.ts | 1 + types/react-jss/lib/injectSheet.d.ts | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/types/react-jss/index.d.ts b/types/react-jss/index.d.ts index 7656897a08..c2ee0a008a 100644 --- a/types/react-jss/index.d.ts +++ b/types/react-jss/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for react-jss 8.6 // Project: https://github.com/cssinjs/react-jss#readme // Definitions by: Sebastian Silbermann +// James Lawrence // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import { createGenerateClassName, JSS, SheetsRegistry } from "jss"; diff --git a/types/react-jss/lib/injectSheet.d.ts b/types/react-jss/lib/injectSheet.d.ts index be3bee933b..5aa3b0925b 100644 --- a/types/react-jss/lib/injectSheet.d.ts +++ b/types/react-jss/lib/injectSheet.d.ts @@ -60,14 +60,12 @@ export type PropInjector = < AdditionalProps >; -type cssNumberOrString = CSS.Properties - // Allow functions that take the properties of the component and return a CSS value export type CssRule = { - [K in keyof cssNumberOrString]: - | (cssNumberOrString[K]) - | ((props: Props) => cssNumberOrString[K]) -}[keyof CSS.Properties] + [K in keyof CSS.Properties]: + | (CSS.Properties[K]) + | ((props: Props) => CSS.Properties[K]) +}[keyof CSS.Properties]; export interface CSSProperties { // Allow pseudo selectors and media queries From 6eb77511162839e409a5dbaeff533006b655a312 Mon Sep 17 00:00:00 2001 From: James Lawrence Date: Thu, 10 Jan 2019 01:05:38 +0000 Subject: [PATCH 0029/1015] Rename to DynamicCSSRule --- types/react-jss/lib/injectSheet.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react-jss/lib/injectSheet.d.ts b/types/react-jss/lib/injectSheet.d.ts index 5aa3b0925b..ef6bdb3dbb 100644 --- a/types/react-jss/lib/injectSheet.d.ts +++ b/types/react-jss/lib/injectSheet.d.ts @@ -61,16 +61,16 @@ export type PropInjector = < >; // Allow functions that take the properties of the component and return a CSS value -export type CssRule = { +export type DynamicCSSRule = { [K in keyof CSS.Properties]: - | (CSS.Properties[K]) + | CSS.Properties[K] | ((props: Props) => CSS.Properties[K]) }[keyof CSS.Properties]; export interface CSSProperties { // Allow pseudo selectors and media queries [k: string]: - | CssRule + | DynamicCSSRule | CSSProperties; } export type Styles = Record< From 3180fea53f4827c599e89369d613b33d4e167048 Mon Sep 17 00:00:00 2001 From: James Lawrence Date: Thu, 10 Jan 2019 01:06:44 +0000 Subject: [PATCH 0030/1015] Update tests - had to disable strict function checking, if anyone knows how to make it work with this, please do! --- types/react-jss/react-jss-tests.tsx | 59 ++++++++++++++++------------- types/react-jss/tsconfig.json | 2 +- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/types/react-jss/react-jss-tests.tsx b/types/react-jss/react-jss-tests.tsx index 803170bb99..6e86bed492 100644 --- a/types/react-jss/react-jss-tests.tsx +++ b/types/react-jss/react-jss-tests.tsx @@ -17,42 +17,44 @@ interface MyTheme { /** * helper function to counter typescripts type widening */ -function createStyles(styles: Styles): Styles { +function createStyles(styles: Styles): Styles { return styles; } -const styles = (theme: MyTheme) => - createStyles({ - myButton: { - color: theme.color.primary, - margin: 1, - "& span": { - fontWeight: "revert" - } - }, - myLabel: { - fontStyle: "italic" - } - }); -interface ButtonProps extends WithSheet { +interface ButtonProps { label: string; + active?: boolean; } -const Button: React.SFC = ({ classes, children }) => { +const styles = (theme: MyTheme) => createStyles({ + myButton: { + color: (props: ButtonProps) => props.active ? 'red': theme.color.primary, + margin: 1, + "& span": { + fontWeight: "revert" + } + }, + myLabel: { + fontStyle: "italic" + } +}); +const Button: React.SFC> = ({active, classes, children}) => { return ( - + <> + + ); }; const ManuallyStyles = () => { return (