From 8eca1512eb4c8fa3418d6355c8fbee2cecb69dc1 Mon Sep 17 00:00:00 2001 From: John McLaughlin Date: Wed, 2 Aug 2017 12:13:39 +0700 Subject: [PATCH 001/218] Fixed types of debug.names and debug.skips arrays. --- types/debug/debug-tests.ts | 1 + types/debug/index.d.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/types/debug/debug-tests.ts b/types/debug/debug-tests.ts index fc8d3c5e56..73a16fe782 100644 --- a/types/debug/debug-tests.ts +++ b/types/debug/debug-tests.ts @@ -12,6 +12,7 @@ log("Formatted test (%d arg)", 1); log("Formatted %s (%d args)", "test", 2); log("Enabled?: %s", debug.enabled("DefinitelyTyped:log")); +log("Name Enabled: %s", debug.names.some(name => name.test("DefinitelyTyped:log"))); log("Namespace: %s", log.namespace); var error:debug.IDebugger = debug("DefinitelyTyped:error"); diff --git a/types/debug/index.d.ts b/types/debug/index.d.ts index 45d3ad02f3..8987b13a26 100644 --- a/types/debug/index.d.ts +++ b/types/debug/index.d.ts @@ -1,6 +1,8 @@ // Type definitions for debug // Project: https://github.com/visionmedia/debug -// Definitions by: Seon-Wook Park , Gal Talmor +// Definitions by: Seon-Wook Park +// Gal Talmor +// John McLaughlin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var debug: debug.IDebug; @@ -16,8 +18,8 @@ declare namespace debug { enable: (namespaces: string) => void, enabled: (namespaces: string) => boolean, - names: string[], - skips: string[], + names: RegExp[], + skips: RegExp[], formatters: IFormatters } From ae870d0deb6f06ae793a764709a39a696ccc8fe2 Mon Sep 17 00:00:00 2001 From: Klaus Kopruch Date: Mon, 9 Jul 2018 14:20:42 +0200 Subject: [PATCH 002/218] added missing type to ObjectSchema::pattern() --- types/joi/index.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index dbf60400b9..1b98750917 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -753,8 +753,11 @@ export interface ObjectSchema extends AnySchema { /** * Specify validation rules for unknown keys matching a pattern. + * + * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names + * @param schema - the schema object matching keys must validate against */ - pattern(regex: RegExp, schema: SchemaLike): this; + pattern(pattern: RegExp | SchemaLike, schema: SchemaLike): this; /** * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well. From e56831f345777cbac0c1003adafcda0d833d3bfc Mon Sep 17 00:00:00 2001 From: Klaus Kopruch Date: Tue, 10 Jul 2018 08:25:09 +0200 Subject: [PATCH 003/218] changed version as requested by reviewer --- types/joi/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index 1b98750917..12aa17b643 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi v13.3.0 +// Type definitions for joi v13.4.0 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers From 589188a626dd89b4e96a2cd6862607d1ef8bddd7 Mon Sep 17 00:00:00 2001 From: Alec Brunelle Date: Thu, 2 Aug 2018 11:12:33 -0400 Subject: [PATCH 004/218] Add types to private functions - Job.moveToCompleted - Job.moveToFailed - Queue.getNextJob - Also add null possibility to Queue.getJob --- types/bull/index.d.ts | 1 + types/bull/v2/index.d.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index a11ae0257a..ac820290f2 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -9,6 +9,7 @@ // David Koblas // Bond Akinmade // Wuha Team +// Alec Brunelle // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/bull/v2/index.d.ts b/types/bull/v2/index.d.ts index 3c89655101..e97920efd7 100644 --- a/types/bull/v2/index.d.ts +++ b/types/bull/v2/index.d.ts @@ -54,6 +54,22 @@ declare module "bull" { * since pubsub does not give any guarantees. */ finished(): Promise; + + /** + * Moves a job to the completed queue and moves a new job from 'waiting' to 'active'. + * @param returnValue The jobs success message. + * @param ignoreLock True when wanting to ignore the redis lock on this job. + * @returns Returns the id of the pulled job. + */ + moveToCompleted(returnValue: string, ignoreLock: boolean): Promise; + + /** + * Moves a job to the failed queue. + * @param errorInfo The jobs error message. + * @param ignoreLock True when wanting to ignore the redis lock on this job. + * @returns void + */ + moveToFailed(errorInfo: ErrorMessage, ignoreLock: boolean): Promise; } export interface Backoff { @@ -204,7 +220,7 @@ declare module "bull" { * Returns a promise that will return the job instance associated with the jobId parameter. * If the specified job cannot be located, the promise callback parameter will be set to null. */ - getJob(jobId: string): Promise; + getJob(jobId: string): Promise; /** * Tells the queue remove all jobs created outside of a grace period in milliseconds. @@ -217,6 +233,18 @@ declare module "bull" { * 'ready', 'error', 'activ', 'progress', 'completed', 'failed', 'paused', 'resumed', 'cleaned' */ on(eventName: string, callback: EventCallback): void; + + /** + * Moves the next job from 'waiting' to 'active'. + * Sets the processedOn timestamp to the current datetime. + * @param jobId If specified, will move a specific job from 'waiting' to 'active', + * @returns Returns the job moved from waiting to active queue. + */ + getNextJob:(jobId?: string) => Promise; + } + + interface ErrorMessage { + message: string; } interface EventCallback { From efeac3258dc2de78b456f90308f1a0a73f64180e Mon Sep 17 00:00:00 2001 From: zaycker Date: Sat, 4 Aug 2018 22:08:24 +0300 Subject: [PATCH 005/218] Added absent rc-select props: to Select: + getInputElement + id + labelInValue + maxTagCount + maxTagPlaceholder + onBlur + onFocus + onInputKeyDown + onPopupScroll + placeholder + showAction + showArrow + tokenSeparators to Option: + title Sorted alph-ly --- types/rc-select/index.d.ts | 60 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/types/rc-select/index.d.ts b/types/rc-select/index.d.ts index b78fc03837..a27ee36784 100644 --- a/types/rc-select/index.d.ts +++ b/types/rc-select/index.d.ts @@ -20,41 +20,55 @@ export { declare namespace RcSelect { interface SelectProps { - className?: string; - prefixCls?: string; - animation?: string; - transitionName?: string; - choiceTransitionName?: string; - dropdownMatchSelectWidth?: boolean; - dropdownClassName?: string; - dropdownStyle?: { [key: string]: string }; - dropdownMenuStyle?: { [key: string]: string }; - notFoundContent?: string; - showSearch?: boolean; allowClear?: boolean; - tags?: boolean; - maxTagTextLength?: number; + animation?: string; + choiceTransitionName?: string; + className?: string; combobox?: boolean; - multiple?: boolean; - disabled?: boolean; - filterOption?: boolean; - optionFilterProp?: string; - optionLabelProp?: string; + defaultActiveFirstOption?: boolean; + defaultLabel?: string | Array; defaultValue?: string | Array; - value?: string | Array; + disabled?: boolean; + dropdownClassName?: string; + dropdownMatchSelectWidth?: boolean; + dropdownMenuStyle?: { [key: string]: string }; + dropdownStyle?: { [key: string]: string }; + filterOption?: boolean; + getPopupContainer?: (trigger: Node) => Node; + getInputElement?: () => Node; + id?: string; + labelInValue?: boolean; + maxTagCount?: number; + maxTagPlaceholder?: React.ReactNode | Function; + maxTagTextLength?: number; + multiple?: boolean; + notFoundContent?: string; + onBlur?: Function; onChange?: (value: string, label: string) => void; + onDeselect?: Function; + onFocus?: Function; + onInputKeyDown?: Function; + onPopupScroll?: Function; onSearch?: Function; onSelect?: (value: string, ontion: Option) => void; - onDeselect?: Function; - defaultLabel?: string | Array; - defaultActiveFirstOption?: boolean; - getPopupContainer?: (trigger: Node) => Node; + optionFilterProp?: string; + optionLabelProp?: string; + placeholder?: React.ReactNode; + prefixCls?: string; + showAction?: string[]; + showArrow?: boolean; + showSearch?: boolean; + tags?: boolean; + tokenSeparators?: string[]; + transitionName?: string; + value?: string | Array; } export class Select extends React.Component { } interface OptionProps { className?: string; disabled?: boolean; key?: string; + title?: string; value?: string; } export class Option extends React.Component { } From 07a575918384b0cd2e3f43a8fcc7e7410bdd43e6 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 5 Aug 2018 17:22:21 -0400 Subject: [PATCH 006/218] Fix issues in geomtries in three.js --- types/three/three-core.d.ts | 80 ++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/types/three/three-core.d.ts b/types/three/three-core.d.ts index 3ede78987f..2d9e46e977 100755 --- a/types/three/three-core.d.ts +++ b/types/three/three-core.d.ts @@ -7093,7 +7093,7 @@ export class SplineCurve extends Curve { // Extras / Geometries ///////////////////////////////////////////////////////////////////// export class BoxBufferGeometry extends BufferGeometry { - constructor(width: number, height: number, depth: number, widthSegments?: number, heightSegments?: number, depthSegments?: number); + constructor(width?: number, height?: number, depth?: number, widthSegments?: number, heightSegments?: number, depthSegments?: number); parameters: { width: number; @@ -7117,7 +7117,7 @@ export class BoxGeometry extends Geometry { * @param heightSegments — Number of segmented faces along the height of the sides. * @param depthSegments — Number of segmented faces along the depth of the sides. */ - constructor(width: number, height: number, depth: number, widthSegments?: number, heightSegments?: number, depthSegments?: number); + constructor(width?: number, height?: number, depth?: number, widthSegments?: number, heightSegments?: number, depthSegments?: number); parameters: { width: number; @@ -7216,29 +7216,39 @@ export class DodecahedronGeometry extends Geometry { } export class EdgesGeometry extends BufferGeometry { - constructor(geometry: BufferGeometry | Geometry, thresholdAngle: number); + constructor(geometry: BufferGeometry | Geometry, thresholdAngle?: number); +} + +export interface ExtrueGeometryOptions { + curveSegments?: number; + steps?: number; + depth?: number; + bevelEnabled?: boolean; + bevelThickness?: number; + bevelSize?: number; + bevelSegments?: number; + extrudePath?: CurvePath; + UVGenerator?: UVGenerator; +} + +export interface UVGenerator { + generateTopUV(geometry: ExtrudeBufferGeometry, vertices: number[], indexA: number, indexB: number, indexC: number): Vector2[]; + generateSideWallUV(geometry: ExtrudeBufferGeometry, vertices: number[], indexA: number, indexB: number, indexC: number, indexD: number): Vector2[]; } export class ExtrudeGeometry extends Geometry { - constructor(shape?: Shape, options?: any); - constructor(shapes?: Shape[], options?: any); + constructor(shape: Shape | Shape[], options?: ExtrueGeometryOptions); - static WorldUVGenerator: { - generateTopUV(geometry: Geometry, vertex: number[], indexA: number, indexB: number, indexC: number): Vector2[]; - generateSideWallUV(geometry: Geometry, vertex: number[], indexA: number, indexB: number, indexC: number, indexD: number): Vector2[]; - }; + static WorldUVGenerator: UVGenerator; addShapeList(shapes: Shape[], options?: any): void; addShape(shape: Shape, options?: any): void; } export class ExtrudeBufferGeometry extends BufferGeometry { - constructor(shapes?: Shape[], options?: any); + constructor(shapes?: Shape[], options?: ExtrueGeometryOptions); - static WorldUVGenerator: { - generateTopUV(geometry: Geometry, vertices: number[], indexA: number, indexB: number, indexC: number): Vector2[]; - generateSideWallUV(geometry: Geometry, vertices: number[], indexA: number, indexB: number, indexC: number, indexD: number): Vector2[]; - }; + static WorldUVGenerator: UVGenerator; addShapeList(shapes: Shape[], options?: any): void; addShape(shape: Shape, options?: any): void; @@ -7282,8 +7292,18 @@ export class OctahedronGeometry extends PolyhedronGeometry { constructor(radius?: number, detail?: number); } +export class ParametricBufferGeometry extends BufferGeometry { + constructor(func: (u: number, v: number, dest: Vector3) => void, slices: number, stacks: number); + + parameters: { + func: (u: number, v: number, dest:Vector3) => void; + slices: number; + stacks: number; + }; +} + export class ParametricGeometry extends Geometry { - constructor(func: (u: number, v: number, dest:Vector3) => void, slices: number, stacks: number); + constructor(func: (u: number, v: number, dest: Vector3) => void, slices: number, stacks: number); parameters: { func: (u: number, v: number, dest:Vector3) => void; @@ -7293,7 +7313,7 @@ export class ParametricGeometry extends Geometry { } export class PlaneBufferGeometry extends BufferGeometry { - constructor(width: number, height: number, widthSegments?: number, heightSegments?: number); + constructor(width?: number, height?: number, widthSegments?: number, heightSegments?: number); parameters: { width: number; @@ -7304,7 +7324,7 @@ export class PlaneBufferGeometry extends BufferGeometry { } export class PlaneGeometry extends Geometry { - constructor(width: number, height: number, widthSegments?: number, heightSegments?: number); + constructor(width?: number, height?: number, widthSegments?: number, heightSegments?: number); parameters: { width: number; @@ -7315,7 +7335,7 @@ export class PlaneGeometry extends Geometry { } export class PolyhedronBufferGeometry extends BufferGeometry { - constructor(vertices: number[], indices: number[], radius: number, detail: number); + constructor(vertices: number[], indices: number[], radius?: number, detail?: number); parameters: { vertices: number[]; @@ -7364,8 +7384,7 @@ export class RingGeometry extends Geometry { } export class ShapeGeometry extends Geometry { - constructor(shape: Shape, options?: any); - constructor(shapes: Shape[], options?: any); + constructor(shapes: Shape | Shape[], curveSegments?: number); addShapeList(shapes: Shape[], options: any): ShapeGeometry; addShape(shape: Shape, options?: any): void; @@ -7377,7 +7396,7 @@ export class ShapeBufferGeometry extends BufferGeometry } export class SphereBufferGeometry extends BufferGeometry { - constructor(radius: number, widthSegments?: number, heightSegments?: number, phiStart?: number, phiLength?: number, thetaStart?: number, thetaLength?: number); + constructor(radius?: number, widthSegments?: number, heightSegments?: number, phiStart?: number, phiLength?: number, thetaStart?: number, thetaLength?: number); parameters: { radius: number; @@ -7405,7 +7424,7 @@ export class SphereGeometry extends Geometry { * @param thetaStart — specify vertical starting angle. Default is 0. * @param thetaLength — specify vertical sweep angle size. Default is Math.PI. */ - constructor(radius: number, widthSegments?: number, heightSegments?: number, phiStart?: number, phiLength?: number, thetaStart?: number, thetaLength?: number); + constructor(radius?: number, widthSegments?: number, heightSegments?: number, phiStart?: number, phiLength?: number, thetaStart?: number, thetaLength?: number); parameters: { radius: number; @@ -7492,7 +7511,7 @@ export class TorusGeometry extends Geometry { } export class TorusKnotBufferGeometry extends BufferGeometry { - constructor(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number, heightScale?: number); + constructor(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number); parameters: { radius: number; @@ -7506,7 +7525,7 @@ export class TorusKnotBufferGeometry extends BufferGeometry { } export class TorusKnotGeometry extends Geometry { - constructor(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number, heightScale?: number); + constructor(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number); parameters: { radius: number; @@ -7520,31 +7539,26 @@ export class TorusKnotGeometry extends Geometry { } export class TubeGeometry extends Geometry { - constructor(path: Curve, segments?: number, radius?: number, radiusSegments?: number, closed?: boolean, taper?: (u: number) => number); + constructor(path: Curve, tubularSegments?: number, radius?: number, radiusSegments?: number, closed?: boolean); parameters: { path: Curve; - segments: number; + tubularSegments: number; radius: number; radialSegments: number; closed: boolean; - taper: (u: number) => number; // NoTaper or SinusoidalTaper; }; tangents: Vector3[]; normals: Vector3[]; binormals: Vector3[]; - - static NoTaper(u?: number): number; - static SinusoidalTaper(u: number): number; - static FrenetFrames(path: Path, segments: number, closed: boolean): void; } export class TubeBufferGeometry extends BufferGeometry { - constructor(path: Curve, segments?: number, radius?: number, radiusSegments?: number, closed?: boolean); + constructor(path: Curve, tubularSegments?: number, radius?: number, radiusSegments?: number, closed?: boolean); parameters: { path: Curve; - segments: number; + tubularSegments: number; radius: number; radialSegments: number; closed: boolean; From 0d35fd2773a8edf050495f2af24ce6747dd36238 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 5 Aug 2018 17:26:07 -0400 Subject: [PATCH 007/218] Update authors --- types/three/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/three/index.d.ts b/types/three/index.d.ts index 8a83de8cae..5e930548ed 100644 --- a/types/three/index.d.ts +++ b/types/three/index.d.ts @@ -17,7 +17,8 @@ // Daniel Hritzkiv , // Apurva Ojas , // Tiger Oakes , -// Seth Kingsley +// Seth Kingsley , +// Methuselah96 // Definitions: https://github.com//DefinitelyTyped export * from "./three-core"; From 0c61f31e93f14ed77ce6b7b2ff84716495834e53 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Tue, 7 Aug 2018 21:26:09 -0400 Subject: [PATCH 008/218] Fix order of parameters --- types/three/three-core.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/three/three-core.d.ts b/types/three/three-core.d.ts index 2d9e46e977..c2a06a0cbd 100755 --- a/types/three/three-core.d.ts +++ b/types/three/three-core.d.ts @@ -7511,13 +7511,13 @@ export class TorusGeometry extends Geometry { } export class TorusKnotBufferGeometry extends BufferGeometry { - constructor(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number); + constructor(radius?: number, tube?: number, tubularSegments?: number, radialSegments?: number, p?: number, q?: number); parameters: { radius: number; tube: number; - radialSegments: number; tubularSegments: number; + radialSegments: number; p: number; q: number; heightScale: number; @@ -7525,13 +7525,13 @@ export class TorusKnotBufferGeometry extends BufferGeometry { } export class TorusKnotGeometry extends Geometry { - constructor(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number); + constructor(radius?: number, tube?: number, tubularSegments?: number, radialSegments?: number, p?: number, q?: number); parameters: { radius: number; tube: number; - radialSegments: number; tubularSegments: number; + radialSegments: number; p: number; q: number; heightScale: number; From b141f33f6698e4128ea979146c585ec7c4ca482d Mon Sep 17 00:00:00 2001 From: Kevin Welcher Date: Fri, 10 Aug 2018 19:05:29 -0400 Subject: [PATCH 009/218] Adds generic Query parameter to next.js's router --- types/next/router.d.ts | 30 ++++++++++++++------------- types/next/test/next-router-tests.tsx | 10 +++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/types/next/router.d.ts b/types/next/router.d.ts index fe3563d473..3072455e45 100644 --- a/types/next/router.d.ts +++ b/types/next/router.d.ts @@ -26,20 +26,22 @@ export type PopStateCallback = (state: any) => boolean | undefined; export type RouterCallback = () => void; -export interface RouterProps { +interface DefaultQuery { + [key: string]: + | boolean + | boolean[] + | number + | number[] + | string + | string[]; +} + +export interface RouterProps { // url property fields readonly pathname: string; readonly route: string; readonly asPath?: string; - readonly query?: { - [key: string]: - | boolean - | boolean[] - | number - | number[] - | string - | string[]; - }; + readonly query?: Q; // property fields readonly components: { @@ -78,14 +80,14 @@ export interface RouterProps { }; } -export interface SingletonRouter extends RouterProps { - router: RouterProps | null; +export interface SingletonRouter extends RouterProps { + router: RouterProps | null; readyCallbacks: RouterCallback[]; ready(cb: RouterCallback): void; } -export interface WithRouterProps { - router: SingletonRouter; +export interface WithRouterProps { + router: SingletonRouter; } export function withRouter( diff --git a/types/next/test/next-router-tests.tsx b/types/next/test/next-router-tests.tsx index fdcf1de3ff..04fa50b912 100644 --- a/types/next/test/next-router-tests.tsx +++ b/types/next/test/next-router-tests.tsx @@ -96,3 +96,13 @@ class TestComponent extends React.Component { } + +const TestSFC: React.SFC = ({ router }) => { + return
{router.query && router.query.test}
; +}; From bdd42596223ecb78682ffa7192a5a15e151a0d61 Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Sat, 11 Aug 2018 13:30:01 +0800 Subject: [PATCH 010/218] update package pidusage`s definition to version 2.0.14 --- types/pidusage/index.d.ts | 56 ++++++++++++++++++++++++--- types/pidusage/pidusage-tests.ts | 27 ++++++++++--- types/pidusage/v1.1/index.d.ts | 12 ++++++ types/pidusage/v1.1/pidusage-tests.ts | 8 ++++ types/pidusage/v1.1/tsconfig.json | 26 +++++++++++++ types/pidusage/v1.1/tslint.json | 3 ++ 6 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 types/pidusage/v1.1/index.d.ts create mode 100644 types/pidusage/v1.1/pidusage-tests.ts create mode 100644 types/pidusage/v1.1/tsconfig.json create mode 100644 types/pidusage/v1.1/tslint.json diff --git a/types/pidusage/index.d.ts b/types/pidusage/index.d.ts index fbe98309b7..a883387a67 100644 --- a/types/pidusage/index.d.ts +++ b/types/pidusage/index.d.ts @@ -1,12 +1,56 @@ -// Type definitions for pidusage 1.1 +// Type definitions for pidusage 2.0 // Project: https://github.com/soyuka/pidusage // Definitions by: Cyril Schumacher +// wujingtao // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export interface Stat { - cpu: number; - memory: number; +/** + * @param pids A pid or a list of pids. + * @param callback Called when the statistics are ready. + */ +declare function pidusage(pids: number | number[] | string | string[], callback: (err: Error | null, stats: pidusage.Stat) => void): void; +/** + * @param pids A pid or a list of pids. + */ +declare function pidusage(pids: number | number[] | string | string[]): Promise; + +declare namespace pidusage { + interface Stat { + /** + * percentage (from 0 to 100*vcore) + */ + cpu: number; + + /** + * bytes + */ + memory: number; + + /** + * PPID + */ + ppid: number; + + /** + * PID + */ + pid: number; + + /** + * ms user + system time + */ + ctime: number; + + /** + * ms since the start of the process + */ + elapsed: number; + + /** + * ms since epoch + */ + timestamp: number; + } } -export function stat(pid: number, callback: (error: Error, stat: Stat) => void): void; -export function unmonitor(pid: number): void; +export = pidusage; diff --git a/types/pidusage/pidusage-tests.ts b/types/pidusage/pidusage-tests.ts index b1d16cbc16..b6835cff18 100644 --- a/types/pidusage/pidusage-tests.ts +++ b/types/pidusage/pidusage-tests.ts @@ -1,8 +1,25 @@ -import pusage = require("pidusage"); +import * as pidusage from 'pidusage'; -pusage.stat(0, (err: Error, stat: pusage.Stat) => { - const cpu = stat.cpu; - const memory = stat.memory; +let cpu: number; +let memory: number; +let ppid: number; +let pid: number; +let ctime: number; +let elapsed: number; +let timestamp: number; + +pidusage(1, (err: Error | null, stats: pidusage.Stat) => { + cpu = stats.cpu; + memory = stats.memory; + ppid = stats.ppid; + pid = stats.pid; + ctime = stats.ctime; + elapsed = stats.elapsed; + timestamp = stats.timestamp; }); -pusage.unmonitor(0); +let stats: Promise; + +stats = pidusage([1, 2]); +stats = pidusage('string'); +stats = pidusage(['string', 'string']); diff --git a/types/pidusage/v1.1/index.d.ts b/types/pidusage/v1.1/index.d.ts new file mode 100644 index 0000000000..fbe98309b7 --- /dev/null +++ b/types/pidusage/v1.1/index.d.ts @@ -0,0 +1,12 @@ +// Type definitions for pidusage 1.1 +// Project: https://github.com/soyuka/pidusage +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Stat { + cpu: number; + memory: number; +} + +export function stat(pid: number, callback: (error: Error, stat: Stat) => void): void; +export function unmonitor(pid: number): void; diff --git a/types/pidusage/v1.1/pidusage-tests.ts b/types/pidusage/v1.1/pidusage-tests.ts new file mode 100644 index 0000000000..b1d16cbc16 --- /dev/null +++ b/types/pidusage/v1.1/pidusage-tests.ts @@ -0,0 +1,8 @@ +import pusage = require("pidusage"); + +pusage.stat(0, (err: Error, stat: pusage.Stat) => { + const cpu = stat.cpu; + const memory = stat.memory; +}); + +pusage.unmonitor(0); diff --git a/types/pidusage/v1.1/tsconfig.json b/types/pidusage/v1.1/tsconfig.json new file mode 100644 index 0000000000..15eed73ebd --- /dev/null +++ b/types/pidusage/v1.1/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "pidusage": [ "pidusage/v1.1" ] + }, + }, + "files": [ + "index.d.ts", + "pidusage-tests.ts" + ] +} \ No newline at end of file diff --git a/types/pidusage/v1.1/tslint.json b/types/pidusage/v1.1/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/pidusage/v1.1/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file From 06bd28a44f40472d00eebc7d177775f876cd2ca1 Mon Sep 17 00:00:00 2001 From: chenshidong Date: Sun, 12 Aug 2018 00:16:31 +0800 Subject: [PATCH 011/218] feat(better-scroll): add typings --- notNeededPackages.json | 6 - types/better-scroll/better-scroll-tests.ts | 68 ++++++ types/better-scroll/index.d.ts | 238 +++++++++++++++++++++ types/better-scroll/tsconfig.json | 24 +++ types/better-scroll/tslint.json | 1 + 5 files changed, 331 insertions(+), 6 deletions(-) create mode 100644 types/better-scroll/better-scroll-tests.ts create mode 100644 types/better-scroll/index.d.ts create mode 100644 types/better-scroll/tsconfig.json create mode 100644 types/better-scroll/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index f630c4e59e..8cb8b15fe4 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -156,12 +156,6 @@ "sourceRepoURL": "https://github.com/brianloveswords/base64url", "asOfVersion": "2.0.0" }, - { - "libraryName": "better-scroll", - "typingsPackageName": "better-scroll", - "sourceRepoURL": "https://github.com/ustbhuangyi/better-scroll", - "asOfVersion": "1.5.0" - }, { "libraryName": "BigInteger.js", "typingsPackageName": "big-integer", diff --git a/types/better-scroll/better-scroll-tests.ts b/types/better-scroll/better-scroll-tests.ts new file mode 100644 index 0000000000..282e6185ab --- /dev/null +++ b/types/better-scroll/better-scroll-tests.ts @@ -0,0 +1,68 @@ +import BScroll from 'better-scroll'; + +const BScroll1 = new BScroll('#wrapper'); +const BScroll2 = new BScroll('#wrapper', { scrollX: false, scrollY: false }); +const BScroll3 = new BScroll('#wrapper', { + snap: true, + wheel: false, + scrollbar: false, + pullDownRefresh: false, +}); +const BScroll4 = new BScroll('#wrapper', { + wheel: { + selectedIndex: 0, + }, +}); +const BScroll6 = new BScroll('#wrapper', { + snap: { + loop: false, + el: document.querySelector('div-test') as Element, + threshold: 0.1, + stepX: 100, + stepY: 100, + listenFlick: true, + }, +}); +const BScroll7 = new BScroll('#wrapper', { + scrollbar: { + fade: true, + }, +}); + +const BScroll8 = new BScroll('#wrapper', { + pullDownRefresh: { + threshold: 50, + stop: 20, + }, +}); + +BScroll1.refresh(); +BScroll1.scrollTo(0, 100); +BScroll1.scrollTo(0, 100, 200); + +BScroll1.scrollToElement('selectedElement'); +BScroll1.scrollToElement('selectedElement', 250); + +BScroll1.scrollToElement(document.getElementById('selectedElement') as HTMLElement); +BScroll1.scrollToElement(document.getElementById('selectedElement') as HTMLElement, 250); + +BScroll2.on('scrollStart', () => { console.log('scroll started'); }); + +const BScroll9 = new BScroll(document.getElementById('wrapper') as HTMLElement); +const BScroll10 = new BScroll(document.getElementById('wrapper') as HTMLElement, { freeScroll: true }); +const BScroll11 = new BScroll(document.getElementById('wrapper') as HTMLElement, { + preventDefaultException: { + tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/, + }, +}); +const BScroll12 = new BScroll(document.getElementById('wrapper') as HTMLElement, { + preventDefaultException: { + className: /(^|\s)test(\s|$)/, + }, +}); + +const BScroll13 = new BScroll(document.getElementById('wrapper') as HTMLElement, { + swipeBounceTime: 1000, +}); + +const BScroll14 = new BScroll('#wrapper', { disableMouse: true, disableTouch: false }); diff --git a/types/better-scroll/index.d.ts b/types/better-scroll/index.d.ts new file mode 100644 index 0000000000..4ce8b2a4c1 --- /dev/null +++ b/types/better-scroll/index.d.ts @@ -0,0 +1,238 @@ +// Type definitions for better-scroll 1.12 +// Project: https://github.com/ustbhuangyi/better-scroll +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.2 +export interface WheelOption { + selectedIndex: number; + rotate: number; + adjustTime: number; + wheelWrapperClass: string; + wheelItemClass: string; +} + +export interface PageOption { + x: number; + y: number; + pageX: number; + pageY: number; +} + +export interface SlideOption { + loop: boolean; + el: Element; + threshold: number; + stepX: number; + stepY: number; + speed: number; + listenFlick: boolean; +} + +export interface ScrollBarOption { + fade: boolean; +} + +export interface PullDownOption { + threshold: number; + stop: number; +} + +export interface PullUpOption { + threshold: number; +} + +export interface BounceObjectOption { + top?: boolean; + bottom?: boolean; + left?: boolean; + right?: boolean; +} + +export interface EaseOption { + swipe?: { + style: string; + fn: (t: number) => number; + }; + swipeBounce?: { + style: string; + fn: (t: number) => number; + }; + bounce?: { + style: string; + fn: (t: number) => number; + }; +} + +export interface BsOption { + startX: number; + startY: number; + scrollX: boolean; + scrollY: boolean; + freeScroll: boolean; + directionLockThreshold: number; + eventPassthrough: string | boolean; + click: boolean; + tap: boolean; + bounce: boolean | BounceObjectOption; + bounceTime: number; + momentum: boolean; + momentumLimitTime: number; + momentumLimitDistance: number; + swipeTime: number; + swipeBounceTime: number; + deceleration: number; + flickLimitTime: number; + flickLimitDistance: number; + resizePolling: number; + probeType: number; + preventDefault: boolean; + preventDefaultException: object; + HWCompositing: boolean; + useTransition: boolean; + useTransform: boolean; + bindToWrapper: boolean; + disableMouse: boolean; + disableTouch: boolean; + observeDOM: boolean; + autoBlur: boolean; + stopPropagation: boolean; + /** + * for picker + * wheel: { + * selectedIndex: 0, + * rotate: 25, + * adjustTime: 400 + * } + */ + wheel: Partial | boolean; + /** + * for slide + * snap: { + * loop: boolean, + * el: domEl, + * threshold: 0.1, + * stepX: 100, + * stepY: 100, + * listenFlick: true + * } + */ + snap: Partial | boolean; + /** + * for scrollbar + * scrollbar: { + * fade: true + * } + */ + scrollbar: Partial | boolean; + /** + * for pull down and refresh + * pullDownRefresh: { + * threshold: 50, + * stop: 20 + * } + */ + pullDownRefresh: Partial | boolean; + /** + * for pull up and load + * pullUpLoad: { + * threshold: 50 + * } + */ + pullUpLoad: Partial | boolean; +} + +export interface Position { + x: number; + y: number; +} + +export default class BScroll { + constructor(element: Element | string, options?: Partial); + + x: number; + y: number; + maxScrollX: number; + maxScrollY: number; + movingDirectionX: number; + movingDirectionY: number; + directionX: number; + directionY: number; + enabled: boolean; + isInTransition: boolean; + isAnimating: boolean; + options: BsOption; + + refresh(): void; + + enable(): void; + + disable(): void; + + scrollBy(x: number, y: number, time?: number, easing?: object): void; + + scrollTo(x: number, y: number, time?: number, easing?: object): void; + + scrollToElement(el: HTMLElement | string, time?: number, offsetX?: number | boolean, offsetY?: number | boolean, easing?: object): void; + + stop(): void; + + destroy(): void; + + goToPage(x: number, y: number, time?: number, easing?: object): void; + + next(time?: number, easing?: object): void; + + prev(time?: number, easing?: object): void; + + getCurrentPage(): PageOption; + + wheelTo(index: number): void; + + getSelectedIndex(): number; + + finishPullDown(): void; + + finishPullUp(): void; + + on( + type: + 'beforeScrollStart' | + 'scrollStart' | + 'scrollCancel' | + 'beforeScrollStart' | + 'flick' | + 'refresh' | + 'destroy' | + 'pullingDown' | + 'pullingUp', + fn: () => any + ): void; + + on( + type: + 'scroll' | + 'scrollEnd' | + 'touchEnd', + fn: (pos: Position) => any + ): void; + + off( + type: + 'beforeScrollStart' | + 'scrollStart' | + 'scroll' | + 'scrollCancel' | + 'beforeScrollStart' | + 'scrollEnd' | + 'touchEnd' | + 'flick' | + 'refresh' | + 'destroy' | + 'pullingDown' | + 'pullingUp', + fn: (...args: any[]) => void + ): void; + + trigger(type: string): void; +} diff --git a/types/better-scroll/tsconfig.json b/types/better-scroll/tsconfig.json new file mode 100644 index 0000000000..26f43ee3bd --- /dev/null +++ b/types/better-scroll/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "better-scroll-tests.ts" + ] +} diff --git a/types/better-scroll/tslint.json b/types/better-scroll/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/better-scroll/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 49d55176a9959b92cde2cb6479773e5eb8709378 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 13 Aug 2018 15:14:43 +0200 Subject: [PATCH 012/218] Add JSON5 missing type --- types/json5/index.d.ts | 15 ++++++++++++++- types/json5/json5-tests.ts | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/types/json5/index.d.ts b/types/json5/index.d.ts index a8fc723b60..8c53949a28 100644 --- a/types/json5/index.d.ts +++ b/types/json5/index.d.ts @@ -40,5 +40,18 @@ Comments Both inline (single-line) and block (multi-line) comments are allowed. */ -declare var json5: JSON; + +type JSONReplacer = (key: string, value: any) => any | (number | string)[] | null; + +interface JSON5 { + // Old JSON methods + parse(text: string, reviver?: (key: any, value: any) => any): any; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; + + // New JSON5 stringify function + stringify(value: any, options?: { space?: number | string, quote?: string, replacer?: JSONReplacer }): string; +} + +declare var json5: JSON5; export = json5; diff --git a/types/json5/json5-tests.ts b/types/json5/json5-tests.ts index f1be5b1038..b92065ccb0 100644 --- a/types/json5/json5-tests.ts +++ b/types/json5/json5-tests.ts @@ -1,7 +1,21 @@ import JSON5 = require('json5'); -var obj = JSON5.parse("{ key:'val', 'key2':[0,1,2,] } //comment "); -var str = JSON5.stringify(obj, null, "\t"); -console.log(str); +const STR = "{ key:'val', 'key2':[0,1,2,] } //comment "; +const OBJ = { key: 'value', key2: [0, 1, 2] }; +function reviverFunction(key: any, value: any): any { + return { [key]: value }; +} + +function replacerFunction(key: string, value: any) { + return { [key]: value }; +} + +const str1: string = JSON5.stringify(OBJ); +const str2: string = JSON5.stringify(OBJ, null, 4); +const str3: string = JSON5.stringify(OBJ, undefined, '2'); +const str4: string = JSON5.stringify(OBJ, replacerFunction, 2); + +JSON.parse(STR); +JSON.parse(STR, reviverFunction); From 8914773fd7787f89c6ca26bdf86bdb0ccfdd5e99 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 13 Aug 2018 15:18:40 +0200 Subject: [PATCH 013/218] Add author --- types/json5/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/json5/index.d.ts b/types/json5/index.d.ts index 8c53949a28..87bda70a2e 100644 --- a/types/json5/index.d.ts +++ b/types/json5/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for JSON5 // Project: http://json5.org/ // Definitions by: Jason Swearingen +// Kacper Wiszczuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From 925a3c466591c17379a1a8f9ac63d2fe6726905b Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 13 Aug 2018 15:27:11 +0200 Subject: [PATCH 014/218] Indentation fixes --- types/json5/index.d.ts | 12 ++++++------ types/json5/json5-tests.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/json5/index.d.ts b/types/json5/index.d.ts index 87bda70a2e..9c0cb6cde6 100644 --- a/types/json5/index.d.ts +++ b/types/json5/index.d.ts @@ -45,13 +45,13 @@ Both inline (single-line) and block (multi-line) comments are allowed. type JSONReplacer = (key: string, value: any) => any | (number | string)[] | null; interface JSON5 { - // Old JSON methods - parse(text: string, reviver?: (key: any, value: any) => any): any; - stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; - stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; + // Old JSON methods + parse(text: string, reviver?: (key: any, value: any) => any): any; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; - // New JSON5 stringify function - stringify(value: any, options?: { space?: number | string, quote?: string, replacer?: JSONReplacer }): string; + // New JSON5 stringify function + stringify(value: any, options?: { space?: number | string, quote?: string, replacer?: JSONReplacer }): string; } declare var json5: JSON5; diff --git a/types/json5/json5-tests.ts b/types/json5/json5-tests.ts index b92065ccb0..94820866f8 100644 --- a/types/json5/json5-tests.ts +++ b/types/json5/json5-tests.ts @@ -5,11 +5,11 @@ const STR = "{ key:'val', 'key2':[0,1,2,] } //comment "; const OBJ = { key: 'value', key2: [0, 1, 2] }; function reviverFunction(key: any, value: any): any { - return { [key]: value }; + return { [key]: value }; } function replacerFunction(key: string, value: any) { - return { [key]: value }; + return { [key]: value }; } const str1: string = JSON5.stringify(OBJ); From dbd0352e7bdfbf38360135df8c77b7f2acf533ff Mon Sep 17 00:00:00 2001 From: Kevin Welcher Date: Mon, 13 Aug 2018 09:52:13 -0400 Subject: [PATCH 015/218] Adds tslint ignore rule --- types/next/router.d.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/types/next/router.d.ts b/types/next/router.d.ts index 3072455e45..2b019625f6 100644 --- a/types/next/router.d.ts +++ b/types/next/router.d.ts @@ -90,8 +90,12 @@ export interface WithRouterProps { router: SingletonRouter; } -export function withRouter( - Component: React.ComponentType, +// Manually disabling the no-unnecessary-generics rule so users can +// retain type inference if they warp their component in withRouter +// without defining props explicitly +export function withRouter( + // tslint:disable-next-line:no-unnecessary-generics + Component: React.ComponentType>, ): React.ComponentType; declare const Router: SingletonRouter; From 327d5763a6384606f6827634b6efcd5bc018733b Mon Sep 17 00:00:00 2001 From: Kevin Welcher Date: Mon, 13 Aug 2018 09:57:11 -0400 Subject: [PATCH 016/218] Adds generic query param to next context as well --- types/next/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 2d87121d61..af4d26aa7f 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -24,11 +24,11 @@ declare namespace next { * Context object used in methods like `getInitialProps()` * <> */ - interface NextContext { + interface NextContext { /** path section of URL */ pathname: string; /** query string section of URL parsed as an object */ - query: QueryStringMapObject; + query: Q; /** String of the actual path (including the query) shows in the browser */ asPath: string; /** HTTP request object (server only) */ From bdf3eeeae8ba9fcf808de764e3af40a359c8b445 Mon Sep 17 00:00:00 2001 From: Kevin Welcher Date: Mon, 13 Aug 2018 15:55:05 -0400 Subject: [PATCH 017/218] Adds query to other cross cutting interfaces --- types/next/app.d.ts | 16 ++++++++-------- types/next/index.d.ts | 6 +++--- types/next/router.d.ts | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/types/next/app.d.ts b/types/next/app.d.ts index e086af0ca8..d077c0e95a 100644 --- a/types/next/app.d.ts +++ b/types/next/app.d.ts @@ -1,19 +1,19 @@ import * as React from "react"; import { NextContext } from "."; -import { RouterProps } from "./router"; +import { RouterProps, DefaultQuery } from "./router"; -export interface AppComponentProps { +export interface AppComponentProps { Component: React.ComponentType; - router: RouterProps; + router: RouterProps; pageProps: any; } -export interface AppComponentContext { +export interface AppComponentContext { Component: React.ComponentType; - router: RouterProps; - ctx: NextContext; + router: RouterProps; + ctx: NextContext; } -export class Container extends React.Component {} +export class Container extends React.Component { } -export default class App extends React.Component {} +export default class App extends React.Component> { } diff --git a/types/next/index.d.ts b/types/next/index.d.ts index af4d26aa7f..71d769ed31 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -43,10 +43,10 @@ declare namespace next { isServer?: boolean; } - type NextSFC = NextStatelessComponent; - interface NextStatelessComponent + type NextSFC = NextStatelessComponent; + interface NextStatelessComponent extends React.StatelessComponent { - getInitialProps?: (ctx: NextContext) => Promise; + getInitialProps?: (ctx: NextContext) => Promise; } type UrlLike = url.UrlObject | url.Url; diff --git a/types/next/router.d.ts b/types/next/router.d.ts index 2b019625f6..be3665e3d5 100644 --- a/types/next/router.d.ts +++ b/types/next/router.d.ts @@ -26,7 +26,7 @@ export type PopStateCallback = (state: any) => boolean | undefined; export type RouterCallback = () => void; -interface DefaultQuery { +export interface DefaultQuery { [key: string]: | boolean | boolean[] From 8bdeb034eada5f0dd3f796fdb4ac16858416d5b2 Mon Sep 17 00:00:00 2001 From: Michael Gauthier Date: Mon, 13 Aug 2018 18:56:36 -0300 Subject: [PATCH 018/218] Add new types for autocomplete session support See: - https://developers.google.com/maps/documentation/javascript/places-autocomplete#session_tokens - https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteSessionToken - https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceDetailsRequest - https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest --- types/googlemaps/googlemaps-tests.ts | 3 ++- types/googlemaps/index.d.ts | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/types/googlemaps/googlemaps-tests.ts b/types/googlemaps/googlemaps-tests.ts index 77a2900b7b..e161e8068e 100644 --- a/types/googlemaps/googlemaps-tests.ts +++ b/types/googlemaps/googlemaps-tests.ts @@ -418,7 +418,8 @@ let service = new google.maps.places.PlacesService(new HTMLDivElement()); service.getDetails({ placeId: '-a1', - fields: ['name'] + fields: ['name'], + sessionToken: new google.maps.places.AutocompleteSessionToken() }, (result, status) => { if (status === google.maps.places.PlacesServiceStatus.NOT_FOUND) { return; diff --git a/types/googlemaps/index.d.ts b/types/googlemaps/index.d.ts index 501dd4c1f8..dba5a5a5a1 100644 --- a/types/googlemaps/index.d.ts +++ b/types/googlemaps/index.d.ts @@ -1,14 +1,15 @@ // Type definitions for Google Maps JavaScript API 3.30 // Project: https://developers.google.com/maps/ -// Definitions by: Folia A/S , -// Chris Wrench , -// Kiarash Ghiaseddin , -// Grant Hutchins , -// Denis Atyasov , -// Michael McMullin , -// Martin Costello , +// Definitions by: Folia A/S , +// Chris Wrench , +// Kiarash Ghiaseddin , +// Grant Hutchins , +// Denis Atyasov , +// Michael McMullin , +// Martin Costello , // Sven Kreiss // Umar Bolatov +// Michael Gauthier // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /* @@ -2542,6 +2543,10 @@ declare namespace google.maps { getQueryPredictions(request: QueryAutocompletionRequest, callback: (result: QueryAutocompletePrediction[], status: PlacesServiceStatus) => void): void; } + export class AutocompleteSessionToken { + constructor(); + } + export interface AutocompletionRequest { bounds?: LatLngBounds|LatLngBoundsLiteral; componentRestrictions?: ComponentRestrictions; @@ -2549,6 +2554,7 @@ declare namespace google.maps { location?: LatLng; offset?: number; radius?: number; + sessionToken?: AutocompleteSessionToken; types?: string[]; } @@ -2566,6 +2572,7 @@ declare namespace google.maps { export interface PlaceDetailsRequest { placeId: string; fields?: string[]; + sessionToken?: AutocompleteSessionToken; } export interface PlaceGeometry { From 7b6c32205b377b1c47937a8a84e6f1da0acb8feb Mon Sep 17 00:00:00 2001 From: Gustavo Brunoro Date: Mon, 13 Aug 2018 20:56:03 -0300 Subject: [PATCH 019/218] react-navigation: add NavigationEvents component --- types/react-navigation/index.d.ts | 11 +++++++++++ types/react-navigation/react-navigation-tests.tsx | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index 6e286c2217..c5ae635725 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -21,6 +21,7 @@ // Ullrich Schaefer // Yosuke Seki // Jake +// Gustavo Brunoro // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -564,6 +565,16 @@ export interface NavigationEventSubscription { remove: () => void; } +export interface NavigationEventsProps extends ViewProps { + navigation?: NavigationNavigator; + onWillFocus?: NavigationEventCallback; + onDidFocus?: NavigationEventCallback; + onWillBlur?: NavigationEventCallback; + onDidBlur?: NavigationEventCallback; +} + +export const NavigationEvents: React.ComponentType; + export interface NavigationScreenProp { state: S; dispatch: NavigationDispatch; diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index 3cde3d892c..0bd5461c6e 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -11,6 +11,7 @@ import { DrawerNavigatorConfig, NavigationAction, NavigationActions, + NavigationEvents, NavigationBackAction, NavigationInitAction, NavigationNavigateAction, @@ -581,3 +582,14 @@ createStackNavigator( routeConfigMap, {transitionConfig: () => ({screenInterpolator: StackViewTransitionConfigs.SlideFromRightIOS.screenInterpolator})} ); + +// Test NavigationEvents component + +const ViewWithNavigationEvents = ( + +); From da4c7c59c46153c1b17bd3e5347e926e1a3f3497 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Tue, 14 Aug 2018 11:36:54 +0200 Subject: [PATCH 020/218] spark-md5: ArrayBuffer.append takes an ArrayBuffer, not a string https://github.com/satazor/js-spark-md5#sparkmd5arraybufferappendarr --- types/spark-md5/index.d.ts | 2 +- types/spark-md5/spark-md5-tests.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/types/spark-md5/index.d.ts b/types/spark-md5/index.d.ts index f856d41e1c..9d5c76f7e2 100644 --- a/types/spark-md5/index.d.ts +++ b/types/spark-md5/index.d.ts @@ -29,7 +29,7 @@ declare class SparkMD5 { declare namespace SparkMD5 { class ArrayBuffer { constructor(); - append(str: string): ArrayBuffer; + append(str: ArrayBufferCopy): ArrayBuffer; end(raw?: boolean): string; reset(): ArrayBuffer; getState(): State; diff --git a/types/spark-md5/spark-md5-tests.ts b/types/spark-md5/spark-md5-tests.ts index 0a6c929a29..6986ee2e89 100644 --- a/types/spark-md5/spark-md5-tests.ts +++ b/types/spark-md5/spark-md5-tests.ts @@ -11,8 +11,7 @@ let hexHash = spark.end(); let rawHash = spark.end(true); const sparkArr = new SparkMD5.ArrayBuffer(); -sparkArr.append('Hi'); -sparkArr.append(' there'); +sparkArr.append(new ArrayBuffer(8)); hexHash = sparkArr.end(); rawHash = sparkArr.end(true); From 989432481b5a3e8a7ca30920c795843e28678c53 Mon Sep 17 00:00:00 2001 From: Arash Outadi Date: Tue, 14 Aug 2018 14:29:35 +0100 Subject: [PATCH 021/218] Add missing option to CheerioOptionsInterface --- types/cheerio/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/cheerio/index.d.ts b/types/cheerio/index.d.ts index d264f4b8da..cb8031705e 100644 --- a/types/cheerio/index.d.ts +++ b/types/cheerio/index.d.ts @@ -214,6 +214,7 @@ interface CheerioOptionsInterface { recognizeCDATA?: boolean; recognizeSelfClosing?: boolean; normalizeWhitespace?: boolean; + ignoreWhitespace?: boolean; } interface CheerioSelector { From 29d688abd6b479800e4a2cf1e4818e79d046a22a Mon Sep 17 00:00:00 2001 From: Andrew Stegmaier Date: Tue, 14 Aug 2018 16:38:26 -0700 Subject: [PATCH 022/218] Fix errors in toastOptions definition, and add complete tests. --- types/jquery-toast-plugin/index.d.ts | 24 ++++++--- .../jquery-toast-plugin-tests.ts | 51 +++++++++++++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/types/jquery-toast-plugin/index.d.ts b/types/jquery-toast-plugin/index.d.ts index 48bff9ff44..db95a9961c 100644 --- a/types/jquery-toast-plugin/index.d.ts +++ b/types/jquery-toast-plugin/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for jquery-toast-plugin 1.3 // Project: https://github.com/kamranahmedse/jquery-toast-plugin // Definitions by: Viqas Hussain +// Andrew Stegmaier // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -13,19 +14,26 @@ interface JQueryStatic { interface toastOptions { text: string; heading?: string; - showHideTransition?: string; + showHideTransition?: 'fade' | 'slide' | 'plain'; allowToastClose?: boolean; - hideAfter?: number; + hideAfter?: number | false; loader?: boolean; loaderBg?: string; - stack?: number; - position?: string; - bgColor?: boolean; - textColor?: boolean; - textAlign?: string; - icon?: boolean; + stack?: number | false; + position?: 'bottom-left' | 'bottom-right' | 'bottom-center' | 'top-right' | 'top-left' | 'top-center' | 'mid-center' | CustomPosition; + bgColor?: string; + textColor?: string; + textAlign?: 'left' | 'right' | 'center'; + icon?: 'info' | 'warning' | 'error' | 'success'; beforeShow?: () => any; afterShown?: () => any; beforeHide?: () => any; afterHidden?: () => any; } + +interface CustomPosition { + left: number | 'auto'; + right: number | 'auto'; + top: number | 'auto'; + bottom: number | 'auto'; +} diff --git a/types/jquery-toast-plugin/jquery-toast-plugin-tests.ts b/types/jquery-toast-plugin/jquery-toast-plugin-tests.ts index d9a2889c9b..d8f21dd200 100644 --- a/types/jquery-toast-plugin/jquery-toast-plugin-tests.ts +++ b/types/jquery-toast-plugin/jquery-toast-plugin-tests.ts @@ -1 +1,52 @@ $.toast({ text: "test" }); + +$.toast({ text: "test", heading: "Test Heading" }); + +$.toast({ text: "test", showHideTransition: "fade" }); +$.toast({ text: "test", showHideTransition: "slide" }); +$.toast({ text: "test", showHideTransition: "plain" }); + +$.toast({ text: "test", allowToastClose: false }); +$.toast({ text: "test", allowToastClose: true }); + +$.toast({ text: "test", hideAfter: 5}); +$.toast({ text: "test", hideAfter: false}); + +$.toast({ text: "test", loader: true }); +$.toast({ text: "test", loader: false }); + +$.toast({ text: "test", loaderBg: "#9EC600" }); + +$.toast({ text: "test", stack: 5}); +$.toast({ text: "test", stack: false}); + +$.toast({ text: "test", position: "bottom-left" }); +$.toast({ text: "test", position: "bottom-right" }); +$.toast({ text: "test", position: "bottom-center" }); +$.toast({ text: "test", position: "top-right" }); +$.toast({ text: "test", position: "top-left" }); +$.toast({ text: "test", position: "top-center" }); +$.toast({ text: "test", position: "mid-center" }); +$.toast({ text: "test", position: { left : "auto", right : 20, top : 20, bottom : "auto" } }); +$.toast({ text: "test", position: { left : 20, right : "auto", top : "auto", bottom : 20 } }); + +$.toast({ text: "test", bgColor: "#9EC600" }); + +$.toast({ text: "test", textColor: "#9EC600" }); + +$.toast({ text: "test", textAlign: "left" }); +$.toast({ text: "test", textAlign: "right" }); +$.toast({ text: "test", textAlign: "center" }); + +$.toast({ text: "test", icon: "info" }); +$.toast({ text: "test", icon: "warning" }); +$.toast({ text: "test", icon: "error" }); +$.toast({ text: "test", icon: "success" }); + +$.toast({ + text: 'Triggers the events', + beforeShow: () => {}, + afterShown: () => {}, + beforeHide: () => {}, + afterHidden: () => {} +}); From 3961ab348445cf7842811ef118120b420aed3291 Mon Sep 17 00:00:00 2001 From: Kodai Nakamura Date: Wed, 15 Aug 2018 15:23:24 +0900 Subject: [PATCH 023/218] Update types --- types/reach__router/index.d.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index f52b3954e3..93727287bd 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -60,13 +60,15 @@ export interface LinkGetProps { export class Link extends React.Component> {} -export interface RedirectProps { +export interface RedirectProps { from?: string; to: string; noThrow?: boolean; + state?: TState; + replace?: boolean; } -export class Redirect extends React.Component {} +export class Redirect extends React.Component> {} export interface MatchProps { path: string; @@ -74,7 +76,7 @@ export interface MatchProps { } export type MatchRenderFn = ( - props: MatchRenderProps, + props: MatchRenderProps ) => React.ReactNode; export interface MatchRenderProps { @@ -104,7 +106,7 @@ export interface LocationProviderProps { } export type LocationProviderRenderFn = ( - context: LocationContext, + context: LocationContext ) => React.ReactNode; export interface LocationContext { From 32e4b4da232f2c0e2eff0b15ee8892ce9b0a3056 Mon Sep 17 00:00:00 2001 From: Kodai Nakamura Date: Wed, 15 Aug 2018 15:33:48 +0900 Subject: [PATCH 024/218] Update test --- types/reach__router/reach__router-tests.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/types/reach__router/reach__router-tests.tsx b/types/reach__router/reach__router-tests.tsx index 56e2305a2e..0cada3367d 100644 --- a/types/reach__router/reach__router-tests.tsx +++ b/types/reach__router/reach__router-tests.tsx @@ -1,4 +1,10 @@ -import { Link, Location, RouteComponentProps, Router } from "@reach/router"; +import { + Link, + Location, + RouteComponentProps, + Router, + Redirect +} from "@reach/router"; import * as React from "react"; import { render } from "react-dom"; @@ -21,9 +27,10 @@ render( + - {(context) => ( + {context => ( <>
hostname is {context.location.hostname}
- * - * - * - * // audio.js - * Page({ - * onReady: function (e) { - * // 使用 wx.createAudioContext 获取 audio 上下文 context - * this.audioCtx = wx.createAudioContext('myAudio') - * this.audioCtx.setSrc('http://ws.stream.qqmusic.qq.com/ - * M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7& - * uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A& - * fromtag=46') - * this.audioCtx.play() - * }, - * data: { - * src: '' - * }, - * audioPlay: function () { - * this.audioCtx.play() - * }, - * audioPause: function () { - * this.audioCtx.pause() - * }, - * audio14: function () { - * this.audioCtx.seek(14) - * }, - * audioStart: function () { - * this.audioCtx.seek(0) - * } - * }) - * @deprecated 1.6.0 - */ - function createAudioContext(audioId: string, instance: any): AudioContext; - interface InnerAudioContext { - /** 当前音频的长度(单位:s),只有在当前有合法的 src 时返 */ - readonly duration: number; - /** 当前音频的播放位置(单位:s),只有在当前有合法的 src 时返回,时间不取整,保留小数点后 6 */ - readonly currentTime: number; - /** 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播 */ - readonly paused: boolean; - /** 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲 */ - readonly buffered: number; - /** 音频的数据链接,用于直接播放。 */ - src: string; - /** 开始播放的位置(单位:s),默认 0 */ - startTime: number; - /** 是否自动开始播放,默认 false */ - autoplay: boolean; - /** 是否循环播放,默认 false */ - loop: boolean; - /** 是否遵循系统静音开关,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音,默认值 true */ - obeyMuteSwitch: boolean; - /** 播放 */ - play(): void; - /** 暂停 */ - pause(): void; - /** 停止 */ - stop(): void; - /** 跳转到指定位置,单位 s */ - seek(position: number): void; - /** 销毁当前实例 */ - destroy(): void; - /** 音频进入可以播放状态,但不保证后面可以流畅播放 */ - onCanplay(callback?: () => void): void; - /** 音频播放事件 */ - onPlay(callback?: () => void): void; - /** 音频暂停事件 */ - onPause(callback?: () => void): void; - /** 音频停止事件 */ - onStop(callback?: () => void): void; - /** 音频自然播放结束事件 */ - onEnded(callback?: () => void): void; - /** 音频播放进度更新事件 */ - onTimeUpdate(callback?: () => void): void; - /** 音频播放错误事件 */ - onError(callback?: () => void): void; - /** 音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 */ - onWaiting(callback?: () => void): void; - /** 音频进行 seek 操作事件 */ - onSeeking(callback?: () => void): void; - /** 音频完成 seek 操作事件 */ - onSeeked(callback?: () => void): void; - } - /** - * 创建并返回内部 audio 上下文 innerAudioContext 对象。 - * 本接口是 wx.createAudioContext 升级版。 - * @version 1.6.0 - */ - function createInnerAudioContext(): InnerAudioContext; - // 媒体-----视频 - interface ChooseVideoOptions extends BaseOptions { - /** album 从相册选视频,camera 使用相机拍摄,默认为:['album', 'camera'] */ - sourceType?: VideoSourceType[]; - /** 拍摄视频最长拍摄时间,单位秒。最长支持60秒 */ - maxDuration?: number; - /** 前置或者后置摄像头,默认为前后都有,即:['front', 'back'] */ - camera?: CameraDevice[]; - /** 接口调用成功,返回视频文件的临时文件路径,详见返回参数说明 */ - success?(res: VideoData): void; - } - /** - * 拍摄视频或从手机相册中选视频,返回视频的临时文件路径。 - */ - function chooseVideo(options: ChooseVideoOptions): void; - // 媒体-----视频组件控制 - interface VideoContext { - /** - * 播放 - */ - play(): void; - /** - * 暂停 - */ - pause(): void; - /** - * 跳转到指定位置,单位 s - */ - seek(position: number): void; - /** - * 发送弹幕,danmu 包含两个属性 text, color。 - */ - sendDanmu(danmu: { - text: string; - color: number | string; - }): void; - } - interface VideoData { - /** 选定视频的临时文件路径 */ - tempFilePath: string; - /** 选定视频的时间长度 */ - duration: number; - /** 选定视频的数据量大小 */ - size: number; - /** 返回选定视频的长 */ - height: number; - /** 返回选定视频的宽 */ - width: number; - } - /** - * 创建并返回 video 上下文 videoContext 对象 - * @param videoId video标签id - */ - function createVideoContext(videoId: string): VideoContext; - interface TakePhotoOptions extends BaseOptions { - /** 成像质量,值为high, normal, low,默认normal */ - quality?: string; - success?(res: { tempImagePath: string }): void; - } - interface StartRecordOptions extends BaseOptions { - /** 超过30s或页面onHide时会结束录像 */ - timeoutCallback?(res: { tempThumbPath: string, tempVideoPath: string }): void; - } - interface StopRecordOptions extends BaseOptions { - success?(res: { tempThumbPath: string, tempVideoPath: string }): void; - } - interface CameraContext { - /** 拍照,可指定质量,成功则返回图片 */ - takePhoto(options: TakePhotoOptions): void; - /** 开始录像 */ - startRecord(options: StartRecordOptions): void; - /** 结束录像,成功则返回封面与视频 */ - stopRecord(options: StopRecordOptions): void; - } - /** - * 创建并返回 camera 上下文 cameraContext 对象 - * cameraContext 与页面的 camera 组件绑定 - * 一个页面只能有一个camera,通过它可以操作对应的 组件。 - * 在自定义组件下,第一个参数传入组件实例this,以操作组件内 组件 - * @version 1.6.0 - */ - function createCameraContext(instance: any): CameraContext; - interface RequestFullScreenOptions extends BaseOptions { - /** 有效值为 0(正常竖向), 90(屏幕逆时针90度), -90(屏幕顺时针90度) */ - direction: number; - } - interface LivePlayerContext { - /** 播放 */ - play(options: BaseOptions): void; - /** 停止 */ - stop(options: BaseOptions): void; - /** 静音 */ - mute(options: BaseOptions): void; - /** 进入全屏 */ - requestFullScreen(options: RequestFullScreenOptions): void; - /** 退出全屏 */ - exitFullScreen(options: BaseOptions): void; - } - /** - * 操作对应的 组件。 - * 创建并返回 live-player 上下文 LivePlayerContext 对象。 - * 在自定义组件下,第二个参数传入组件实例this,以操作组件内 组件 - * @version 1.7.0 - */ - function createLivePlayerContext(id: string, instance: any): LivePlayerContext; - // 文件 - interface SavedFileData { - /** 文件的保存路径 */ - savedFilePath: string; - } - interface SaveFileOptions extends BaseOptions { - /** 需要保存的文件的临时路径 */ - tempFilePath: string; - /** 返回文件的保存路径,res = {savedFilePath: '文件的保存路径'} */ - success?(res: SavedFileData): void; - } - /** - * 保存文件到本地。 - * 本地文件存储的大小限制为 10M - */ - function saveFile(options: SaveFileOptions): void; - interface File { - /** - * 文件的本地路径 - */ - filePath: string; - /** - * 文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数 - */ - createTime: number; - /** - * 文件大小,单位B - */ - size: number; - } - interface GetFileInfoOptions extends BaseOptions { - /** 本地文件路径 */ - filePath: string; - /** 计算文件摘要的算法,默认值 md5,有效值:md5,sha1 */ - digestAlgorithm?: string; - success?(options: GetFileInfoSuccess): void; - } - interface GetFileInfoSuccess { - /** 文件大小,单位:B */ - size: number; - /** 按照传入的 digestAlgorithm 计算得出的的文件摘要 */ - digest: string; - /** 调用结果 */ - errMsg: string; - } - /** - * 获取文件信息 - * @version 1.4.0 - */ - function getFileInfo(options: GetFileInfoOptions): void; - interface GetSavedFileListData { - /** - * 接口调用结果 - */ - errMsg: string; - /** - * 文件列表 - */ - fileList: File[]; - } - interface GetSavedFileListOptions extends BaseOptions { - /** 接口调用成功的回调函数 */ - success?(res: GetSavedFileListData): void; - } - /** - * 获取本地已保存的文件列表 - */ - function getSavedFileList(options: GetSavedFileListOptions): void; - interface SavedFileInfoData { - /** - * 接口调用结果 - */ - errMsg: string; - /** - * 文件大小,单位B - */ - size: number; - /** - * 文件的保存是的时间戳,从1970/01/01 08:00:00 到当前时间的秒数 - */ - createTime: number; - } - interface GetSavedFileInfoOptions extends BaseOptions { - filePath: string; - /** 接口调用成功的回调函数 */ - success?(res: SavedFileInfoData): void; - } - /** - * 获取本地文件的文件信息 - */ - function getSavedFileInfo(options: GetSavedFileInfoOptions): void; - type RemoveSavedFileOptions = BaseOptions; - /** - * 删除本地存储的文件 - */ - function removeSavedFile(options: RemoveSavedFileOptions): void; - interface OpenDocumentOptions extends BaseOptions { - /** - * 文件路径,可通过 downFile 获得 - */ - filePath: string; - } - /** - * 新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx - */ - function openDocument(options: OpenDocumentOptions): void; - // 数据缓存 - interface SetStorageOptions extends BaseOptions { - /** 本地缓存中的指定的 key */ - key: string; - /** 需要存储的内容 */ - data: any | string; - } - /** - * 将数据存储在本地缓存中指定的 key 中, - * 会覆盖掉原来该 key 对应的内容,这是一个异步接口。 - */ - function setStorage(options: SetStorageOptions): void; - /** - * 将 data 存储在本地缓存中指定的 key 中, - * 会覆盖掉原来该 key 对应的内容,这是一个同步接口。 - * - * @param key 本地缓存中的指定的 key - * @param data 需要存储的内容 - */ - function setStorageSync(key: string, data: any | string): void; - interface GetStorageOptions extends BaseOptions { - /** 本地缓存中的指定的 key */ - key: string; - /** 接口调用的回调函数,res = {data: key对应的内容} */ - success(res: DataResponse): void; - } - /** - * 从本地缓存中异步获取指定 key 对应的内容。 - */ - function getStorage(options: GetStorageOptions): void; - /** - * 从本地缓存中同步获取指定 key 对应的内容。 - * - */ - function getStorageSync(key: string): any | string; - interface StorageInfo { - /** - * 当前storage中所有的key - */ - keys: string[]; - /** - * 当前占用的空间大小, 单位kb - */ - currentSize: number; - /** - * 限制的空间大小,单位kb - */ - limitSize: number; - } - interface GetStorageInfoOptions extends BaseOptions { - success(res: StorageInfo): void; - } - /** - * 异步获取当前storage的相关信息 - */ - function getStorageInfo(options: GetStorageInfoOptions): void; - function getStorageInfoSync(): GetStorageInfoOptions; - interface RemoveStorageOptions extends BaseOptions { - key: string; - success?(res: DataResponse): void; - } - function removeStorage(options: RemoveStorageOptions): void; - function removeStorageSync(key: string): DataResponse; - /** - * 清理本地数据缓存。 - */ - function clearStorage(): void; - /** - * 同步清理本地数据缓存 - */ - function clearStorageSync(): void; - // #endregion - // #region 位置API列表 - // 位置-----获取位置 - interface LocationData { - /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ - latitude: number; - /** 经度,浮点数,范围为-180~180,负数表示西经 */ - longitude: number; - /** 速度,浮点数,单位m/s */ - speed: number; - /** 位置的精确度 */ - accuracy: number; - } - interface GetLocationOptions extends BaseOptions { - /** 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于wx.openLocation的坐标 */ - type?: 'wgs84' | 'gcj02'; - /** 接口调用成功的回调函数,返回内容详见返回参数说明。 */ - success(res: LocationData): void; - } - /** - * 获取当前的地理位置、速度。 - */ - function getLocation(options: GetLocationOptions): void; - interface ChooseLocationData { - /** - * 位置名称 - */ - name: string; - /** - * 详细地址 - */ - address: string; - /** - * 纬度,浮点数,范围为-90~90,负数表示南纬 - */ - latitude: number; - /** - * 经度,浮点数,范围为-180~180,负数表示西经 - */ - longitude: number; - } - interface ChooseLocationOptions extends BaseOptions { - success(res: ChooseLocationData): void; - } - /** - * 打开地图选择位置 - */ - function chooseLocation(options: ChooseLocationOptions): void; - // 位置-----查看位置 - interface OpenLocationOptions extends BaseOptions { - /** 纬度,范围为-90~90,负数表示南纬 */ - latitude: number; - /** 经度,范围为-180~180,负数表示西经 */ - longitude: number; - /** 缩放比例,范围1~28,默认为28 */ - scale?: number; - /** 位置名 */ - name?: string; - /** 地址的详细说明 */ - address?: string; - } - /** - * 使用微信内置地图查看位置 - */ - function openLocation(options: OpenLocationOptions): void; - // 位置-----地图组件控制 - interface GetCenterLocationOptions extends BaseOptions { - success(res: { - longitude: number; - latitude: number; - }): void; - } - /** - * mapContext 通过 mapId 跟一个 组件绑定,通过它可以操作对应的 组件。 - */ - interface MapContext { - /** - * 获取当前地图中心的经纬度,返回的是 gcj02 坐标系,可以用于 wx.openLocation - */ - getCenterLocation(options: GetCenterLocationOptions): OpenLocationOptions; - /** - * 将地图中心移动到当前定位点,需要配合map组件的show-location使用 - */ - moveToLocation(): void; - } - /** - * 创建并返回 map 上下文 mapContext 对象 - */ - function createMapContext(mapId: string): MapContext; - // #endregion - // #region 设备API列表 - // 设备-----系统信息 - interface SystemInfo { - /** 手机型号 */ - model: string; - /** 设备像素比 */ - pixelRatio: number; - /** 窗口宽度 */ - windowWidth: number; - /** 窗口高度 */ - windowHeight: number; - /** 微信设置的语言 */ - language: string; - /** 微信版本号 */ - version: string; - } - interface GetSystemInfoOptions extends BaseOptions { - /** 成功获取系统信息的回调 */ - success(res: SystemInfo): void; - } - /** - * 获取系统信息。 - */ - function getSystemInfo(options: GetSystemInfoOptions): void; - function getSystemInfoSync(): SystemInfo; - /** - * 判断小程序的API,回调,参数,组件等是否在当前版本可用。 - * String参数说明: - * 使用 ${API}.${method}.${param}.${options} - * 或者 ${component}.${attribute}.${option}方式来调用 - * 例如: - * ${API} 代表 API 名字 - * ${method} 代表调用方式,有效值为return, success, object, callback - * ${param} 代表参数或者返回值 - * ${options} 代表参数的可选值 - * ${component} 代表组件名字 - * ${attribute} 代表组件属性 - * ${option} 代表组件属性的可选值 - */ - function canIUse(api: string): boolean; - // 设备-----网络状态 - type networkType = '2g' | '3g' | '4g' | 'wifi' | 'unknown' | 'none'; - interface NetworkTypeData { - /** 返回网络类型2g,3g,4g,wifi */ - networkType: networkType; - } - interface GetNetworkTypeOptions extends BaseOptions { - /** 接口调用成功,返回网络类型 networkType */ - success(res: NetworkTypeData): void; - } - /** - * 获取网络类型。 - */ - function getNetworkType(options: GetNetworkTypeOptions): void; - /** - * 监听网络状态变化。 - * 微信客户端 6.5.6 版本开始支持 - * @version 1.1.0 - */ - function onNetworkStatusChange(callback: (res: { - isConnected: boolean; - networkType: networkType; - }) => void): void; - // 设备-----加速度计 - interface AccelerometerData { - /** X 轴 */ - x: number; - /** Y 轴 */ - y: number; - /** Z 轴 */ - z: number; - } - type AccelerometerChangeCallback = (res: AccelerometerData) => void; - /** - * 监听重力感应数据,频率:5次/秒 - */ - function onAccelerometerChange(callback: AccelerometerChangeCallback): void; - type AccelerometerOptions = BaseOptions; - /** - * 开始监听加速度数据。 - * 微信客户端 6.5.6 版本开始支持 - * @version 1.1.0 - */ - function startAccelerometer(options: AccelerometerOptions): void; - /** - * 停止监听加速度数据。 - * 微信客户端 6.5.6 版本开始支持 - * @version 1.1.0 - */ - function stopAccelerometer(options: AccelerometerOptions): void; - // 设备-----罗盘 - interface CompassData { - /** 面对的方向度数 */ - direction: number; - } - type CompassChangeCallback = (res: CompassData) => void; - /** - * 监听罗盘数据,频率:5次/秒,接口调用后会自动开始监听,可使用wx.stopCompass停止监听。 - */ - function onCompassChange(callback: CompassChangeCallback): void; - type CompassOptions = BaseOptions; - /** - * 开始监听罗盘数据。 - * 微信客户端 6.5.6 版本开始支持 - * @version 1.1.0 - */ - function startCompass(options: CompassOptions): void; - function stopCompass(options: CompassOptions): void; - // 设备-----拨打电话 - interface MakePhoneCallOptions extends BaseOptions { - /** - * 需要拨打的电话号码 - */ - phoneNumber: string; - } - /** - * 拨打电话 - */ - function makePhoneCall(options: MakePhoneCallOptions): void; - // 设备-----扫码 - type scanType = "qrCode" | "barCode"; - interface ScanCodeData { - /** - * 所扫码的内容 - */ - result: string; - /** - * 所扫码的类型 - */ - scanType: scanType; - /** - * 所扫码的字符集 - */ - charSet: string; - /** - * 当所扫的码为当前小程序的合法二维码时,会返回此字段,内容为二维码携带的 path - */ - path: string; - } - interface ScanCodeOptions extends BaseOptions { - /** - * 是否只能从相机扫码,不允许从相册选择图片 - * @version 1.2.0 - */ - onlyFromCamera?: boolean; - /** - * 扫码类型,参数类型是数组 - * 二维码是'qrCode',一维码是'barCode',DataMatrix是‘datamatrix’,pdf417是‘pdf417’。 - * @version 1.7.0 - */ - scanType?: string[]; - success(res: ScanCodeData): void; - } - /** - * 调起客户端扫码界面,扫码成功后返回对应的结果 - */ - function scanCode(options: ScanCodeOptions): void; - // 设备-----剪贴板 - interface ClipboardDataOptions extends BaseOptions { - data: string; - success?(res: DataResponse): void; - } - /** - * 设置系统剪贴板的内容 - * 微信客户端 6.5.6 版本开始支持 - * @version 1.1.0 - */ - function setClipboardData(options: ClipboardDataOptions): void; - /** - * 获取系统剪贴板内容 - * 微信客户端 6.5.6 版本开始支持 - * @version 1.1.0 - */ - function getClipboardData(options: ClipboardDataOptions): void; - // 设备-----蓝牙 - interface OpenBluetoothAdapterOptions extends BaseOptions { - success(res: any): void; - } - /** - * 初始化蓝牙适配器 - * @version 1.1.0 - */ - function openBluetoothAdapter(options: OpenBluetoothAdapterOptions): void; - interface CloseBluetoothAdapterOptions extends BaseOptions { - success(res: any): void; - } - /** - * 关闭蓝牙模块。调用该方法将断开所有已建立的链接并释放系统资源 - * @version 1.1.0 - */ - function closeBluetoothAdapter(options: CloseBluetoothAdapterOptions): void; - interface BluetoothAdapterState { - /** - * 蓝牙适配器是否可用 - */ - available: boolean; - /** - * 蓝牙适配器是否处于搜索状态 - */ - discovering: boolean; - } - interface BluetoothAdapterStateData extends ErrMsgResponse { - /** - * 蓝牙适配器信息 - */ - adapterState: BluetoothAdapterState; - } - interface GetBluetoothAdapterStateOptions extends BaseOptions { - success(res: BluetoothAdapterStateData): void; - } - /** - * 获取本机蓝牙适配器状态 - * @version 1.1.0 - */ - function getBluetoothAdapterState(options: GetBluetoothAdapterStateOptions): void; - /** - * 监听蓝牙适配器状态变化事件 - * @version 1.1.0 - */ - function onBluetoothAdapterStateChange(callback: (res: BluetoothAdapterState) => void): void; - interface StartBluetoothDevicesDiscoveryOptions extends BaseOptions { - success(res: ErrMsgResponse): void; - /** - * 蓝牙设备主 service 的 uuid 列表 - * 某些蓝牙设备会广播自己的主 service 的 uuid。如果这里传入该数组,那么根据该 uuid 列表,只搜索有这个主服务的设备。 - */ - services?: string[]; - } - /** - * 开始搜寻附近的蓝牙外围设备。 - * 注意,该操作比较耗费系统资源,请在搜索并连接到设备后调用 stop 方法停止搜索。 - * @example - * // 以微信硬件平台的蓝牙智能灯为例,主服务的 UUID 是 FEE7。传入这个参数,只搜索主服务 UUID 为 FEE7 的设备 - * wx.startBluetoothDevicesDiscovery({ - * services: ['FEE7'], - * success: function (res) { - * console.log(res) - * } - * }); - */ - function startBluetoothDevicesDiscovery(options: StartBluetoothDevicesDiscoveryOptions): void; - interface StopBluetoothDevicesDiscoveryOptions extends BaseOptions { - success(res: ErrMsgResponse): void; - } - /** - * 停止搜寻附近的蓝牙外围设备。请在确保找到需要连接的设备后调用该方法停止搜索。 - * @version 1.1.0 - */ - function stopBluetoothDevicesDiscovery(options: StopBluetoothDevicesDiscoveryOptions): void; - /** - * 蓝牙设备信息 - */ - interface BluetoothDevice { - /** - * 蓝牙设备名称,某些设备可能没有 - */ - name: string; - /** - * 用于区分设备的 id - */ - deviceId: string; - /** - * int 当前蓝牙设备的信号强度 - */ - RSSI: number; - /** - * 当前蓝牙设备的广播内容 - */ - advertisData: ArrayBuffer; - } - interface GetBluetoothDevicesOptions extends BaseOptions { - success(res: { - devices: BluetoothDevice[]; - } & ErrMsgResponse): void; - } - /** - * 获取所有已发现的蓝牙设备,包括已经和本机处于连接状态的设备 - */ - function getBluetoothDevices(options: GetBluetoothDevicesOptions): void; - /** - * 监听寻找到新设备的事件 - * @version 1.1.0 - */ - function onBluetoothDeviceFound(callback: (res: { - devices: BluetoothDevice[] - }) => void): void; - interface GetConnectedBluetoothDevicesOptions extends BaseOptions { - services: string[]; - success(res: { - devices: BluetoothDevice[] - } & ErrMsgResponse): void; - } - /** - * 根据 uuid 获取处于已连接状态的设备 - * @version 1.1.0 - */ - function getConnectedBluetoothDevices(options: GetConnectedBluetoothDevicesOptions): void; - interface CreateBLEConnectionOptions extends BaseOptions { - success(res: ErrMsgResponse): void; - } - /** - * 低功耗蓝牙接口 - * @version 1.1.0 - */ - function createBLEConnection(options: CreateBLEConnectionOptions): void; - interface CloseBLEConnectionOptions extends BaseOptions { - /** - * 蓝牙设备 id,参考 getDevices 接口 - */ - deviceId: string; - success(res: ErrMsgResponse): void; - } - /** - * 断开与低功耗蓝牙设备的连接 - * @version 1.1.0 - */ - function closeBLEConnection(options: CloseBLEConnectionOptions): void; - interface GetBLEDeviceServicesOptions extends BaseOptions { - /** - * 蓝牙设备 id,参考 getDevices 接口 - */ - deviceId: string; - /** - * 成功则返回本机蓝牙适配器状态 - */ - success(res: { - services: Array<{ - uuid: string; - isPrimary: boolean; - }>; - } & ErrMsgResponse): void; - } - /** - * 获取蓝牙设备所有 service(服务) - */ - function getBLEDeviceServices(options: GetBLEDeviceServicesOptions): void; - interface GetBLEDeviceCharacteristicsOptions extends BaseOptions { - /** - * 蓝牙设备 id,参考 device 对象 - */ - deviceId: string; - /** - * 蓝牙服务 uuid - */ - serviceId: string; - /** - * 成功则返回本机蓝牙适配器状态 - */ - success(res: { - characteristics: Array<{ - uuid: string; - properties: Array<{ - /** - * 该特征值是否支持 read 操作 - */ - read: boolean; - /** - * 该特征值是否支持 write 操作 - */ - write: boolean; - /** - * 该特征值是否支持 notify 操作 - */ - notify: boolean; - /** - * 该特征值是否支持 indicate 操作 - */ - indicate: boolean; - }>; - }>; - } & ErrMsgResponse): void; - } - /** - * 获取蓝牙设备所有 characteristic(特征值) - */ - function getBLEDeviceCharacteristics(options: GetBLEDeviceCharacteristicsOptions): void; - interface BLECharacteristicValueOptions extends BaseOptions { - /** - * 蓝牙设备 id,参考 device 对象 - */ - deviceId: string; - /** - * 蓝牙特征值对应服务的 uuid - */ - serviceId: string; - /** - * 蓝牙特征值的 uuid - */ - characteristicId: string; - success(res: { - characteristic: { + // #region 基本参数 + interface DataResponse { + /** 回调函数返回的内容 */ + data: object | string | ArrayBuffer; + /** 开发者服务器返回的 HTTP 状态码 */ + statusCode: number; + /** 开发者服务器返回的 HTTP Response Header */ + header: object; + } + interface ErrMsgResponse { + /** 成功:ok,错误:详细信息 */ + errMsg: "ok" | string; + } + interface TempFileResponse { + /** 文件的临时路径 */ + tempFilePath: string; + } + interface BaseOptions { + /** 接口调用成功的回调函数 */ + success?(res: any): void; + /** 接口调用失败的回调函数 */ + fail?(res: any): void; + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?(res: any): void; + } + // #endregion + // #region 网络API列表 + // 发起请求 + interface RequestHeader { + [key: string]: string; + } + interface RequestOptions extends BaseOptions { + /** 开发者服务器接口地址 */ + url: string; + /** 请求的参数 */ + data?: string | object | ArrayBuffer; + /** 设置请求的 header , header 中不能设置 Referer */ + header?: RequestHeader; + /** 默认为 GET,有效值:OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT */ + method?: + | "GET" + | "OPTIONS" + | "GET" + | "HEAD" + | "POST" + | "PUT" + | "DELETE" + | "TRACE" + | "CONNECT"; + /** 如果设为json,会尝试对返回的数据做一次 JSON.parse */ + dataType?: string; /** - * 蓝牙设备特征值的 uuid + * 设置响应的数据类型。合法值:text、arraybuffer + * @version 1.7.0 */ - characteristicId: string; + responseType?: string; + /** 收到开发者服务成功返回的回调函数,res = {data: '开发者服务器返回的内容'} */ + success?(res: DataResponse): void; + } + /** + * wx.request发起的是https请求。一个微信小程序,同时只能有5个网络请求连接。 + */ + function request(options: RequestOptions): RequestTask; + + /** + * 返回一个 requestTask 对象,通过 requestTask,可中断请求任务。 + */ + interface RequestTask { + abort(): void; + } + + interface UploadTask { /** - * 蓝牙设备特征值对应服务的 uuid + * 监听上传进度变化 + * @version 1.4.0 + */ + onProgressUpdate( + callback?: ( + res: { + /** 上传进度百分比 */ + progress: number; + /** 已经上传的数据长度,单位 Bytes */ + totalBytesSent: number; + /** 预期需要上传的数据总长度,单位 Bytes */ + totalBytesExpectedToSend: number; + } + ) => void + ): void; + /** + * 中断下载任务 + * @version 1.4.0 + */ + abort(): void; + } + // 上传下载 + interface UploadFileOptions extends BaseOptions { + /** 开发者服务器 url */ + url: string; + /** 要上传文件资源的路径 */ + filePath: string; + /** 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容 */ + name: string; + /** HTTP 请求 Header , header 中不能设置 Referer */ + header?: RequestHeader; + /** HTTP 请求中其他额外的 form data */ + formData?: any; + } + /** + * 将本地资源上传到开发者服务器。 + * 如页面通过 wx.chooseImage 等接口获取到一个本地资源的临时文件路径后, + * 可通过此接口将本地资源上传到指定服务器。 + * 客户端发起一个 HTTPS POST 请求, + * 其中 Content-Type 为 multipart/form-data 。 + */ + function uploadFile(options: UploadFileOptions): UploadTask; + interface DownloadTask { + /** + * 监听下载进度变化 + * @version 1.4.0 + */ + onProgressUpdate( + callback?: ( + res: { + /** 下载进度百分比 */ + progress: number; + /** 已经下载的数据长度,单位 Bytes */ + totalBytesWritten: number; + /** 预期需要下载的数据总长度,单位 Bytes */ + totalBytesExpectedToWrite: number; + } + ) => void + ): void; + /** + * 中断下载任务 + * @version 1.4.0 + */ + abort(): void; + } + interface DownloadFileOptions extends BaseOptions { + /** 下载资源的 url */ + url: string; + /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ + type?: string; + /** HTTP 请求 Header */ + header?: RequestHeader; + /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ + success?(res: TempFileResponse): void; + } + /** + * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, + * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 + */ + function downloadFile(options: DownloadFileOptions): DownloadTask; + // WebSocket + interface ConnectSocketOptions extends BaseOptions { + /** 开发者服务器接口地址,必须是 HTTPS 协议,且域名必须是后台配置的合法域名 */ + url: string; + /** 请求的数据 */ + data?: any; + /** HTTP Header , header 中不能设置 Referer */ + header?: RequestHeader; + /** 默认是GET,有效值为: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT */ + method?: string; + /** + * 子协议数组 + * @version 1.4.0 + */ + protocols?: string[]; + } + /** + * 创建一个 WebSocket 连接; + * 一个微信小程序同时只能有一个 WebSocket 连接, + * 如果当前已存在一个 WebSocket 连接, + * 会自动关闭该连接,并重新创建一个 WebSocket 连接。 + */ + function connectSocket(options: ConnectSocketOptions): void; + /** 监听WebSocket连接打开事件。 */ + function onSocketOpen(callback: () => void): void; + /** 监听WebSocket错误。 */ + function onSocketError(callback: (error: any) => void): void; + interface SendSocketMessageOptions extends BaseOptions { + /** 需要发送的内容 */ + data: string; + } + /** + * 通过 WebSocket 连接发送数据,需要先 wx.connectSocket, + * 并在 wx.onSocketOpen 回调之后才能发送。 + */ + function sendSocketMessage(options: SendSocketMessageOptions): void; + /** + * 监听WebSocket接受到服务器的消息事件。 + */ + function onSocketMessage(callback: (res: DataResponse) => void): void; + /** + * 关闭WebSocket连接。 + */ + function closeSocket(): void; + /** 监听WebSocket关闭。 */ + function onSocketClose(callback: () => void): void; + // #endregion + // #region 媒体API列表 + // 媒体-----图片 + type ImageSizeType = "original" | "compressed"; + type ImageSourceType = "album" | "camera"; + type VideoSourceType = "album" | "camera"; + type CameraDevice = "front" | "back"; + interface TempFile { + /** 本地文件路径 */ + path: string; + /** 本地文件大小,单位:B */ + size: number; + } + interface TempFilesData { + /** 文件的临时路径 */ + tempFilePaths: string; + /** + * 图片的本地文件列表,每一项是一个 File 对象 + * @version 1.2.0 + */ + tempFiles: TempFile[]; + } + interface ChooseImageOptions extends BaseOptions { + /** 最多可以选择的图片张数,默认9 */ + count?: number; + /** original 原图,compressed 压缩图,默认二者都有 */ + sizeType?: ImageSizeType[]; + /** album 从相册选图,camera 使用相机,默认二者都有 */ + sourceType?: ImageSourceType[]; + /** 成功则返回图片的本地文件路径列表 tempFilePaths */ + success(res: TempFilesData): void; + } + /** + * 从本地相册选择图片或使用相机拍照。 + */ + function chooseImage(options: ChooseImageOptions): void; + interface PreviewImageOptions extends BaseOptions { + /** 当前显示图片的链接,不填则默认为 urls 的第一张 */ + current?: string; + /** 需要预览的图片链接列表 */ + urls: string[]; + } + /** + * 预览图片。 + */ + function previewImage(options: PreviewImageOptions): void; + interface GetImageInfoOptions extends BaseOptions { + /** + * 图片的路径,可以是相对路径,临时文件路径,存储文件路径,网络图片路径 + */ + src: string; + } + /** + * 获取图片信息 + */ + function getImageInfo(options: GetImageInfoOptions): void; + interface SaveImageToPhotosAlbumOptions extends BaseOptions { + /** + * 图片的路径,可以是相对路径,临时文件路径,存储文件路径,网络图片路径 + */ + filePath: string; + success(res: { errMsg: string }): void; + } + /** + * 保存图片到系统相册。 + * 需要用户授权 scope.writePhotosAlbum + * @version 1.2.0 + */ + function saveImageToPhotosAlbum( + options: SaveImageToPhotosAlbumOptions + ): void; + // 媒体-----录音 + interface StartRecordOptions extends BaseOptions { + /** 录音成功后调用,返回录音文件的临时文件路径,res = {tempFilePath: '录音文件的临时路径'} */ + success?(res: TempFileResponse): void; + } + /** + * 开始录音。当主动调用wx.stopRecord, + * 或者录音超过1分钟时自动结束录音,返回录音文件的临时文件路径。 + * 注:文件的临时路径,在小程序本次启动期间可以正常使用, + * 如需持久保存,需在主动调用wx.saveFile,在小程序下次启动时才能访问得到。 + * @deprecated 1.6.0 + */ + function startRecord(options: StartRecordOptions): void; + interface StopRecordOptions extends BaseOptions { + success?(): void; + } + /** + * 主动调用停止录音。 + */ + function stopRecord(options?: StopRecordOptions): void; + type EncodeBitRate = + | 8000 + | 11025 + | 12000 + | 16000 + | 22050 + | 24000 + | 32000 + | 44100 + | 48000; + interface RecorderManagerStartOptions { + /** + * 指定录音的时长,单位 ms + * 如果传入了合法的 duration + * 在到达指定的 duration 后会自动停止录音,最大值 600000(10 分钟),默认值 60000(1 分钟) + */ + duration?: number; + /** + * 采样率,有效值 8000/16000/44100 + */ + sampleRate?: number; + /** + * 否 录音通道数,有效值 1/2 + */ + numberOfChannels?: number; + /** + * 编码码率 + * 采样率和码率有一定要求,具体有效值如下: + * 采样率 编码码率 + * + 8000 16000 ~ 48000 + * + 11025 16000 ~ 48000 + * + 12000 24000 ~ 64000 + * + 16000 24000 ~ 96000 + * + 22050 32000 ~ 128000 + * + 24000 32000 ~ 128000 + * + 32000 48000 ~ 192000 + * + 44100 64000 ~ 320000 + * + 48000 64000 ~ 320000 + */ + encodeBitRate: number; + /** 音频格式,有效值 aac/mp3 */ + format: string; + /** + * 指定帧大小,单位 KB + * 传入 frameSize 后,每录制指定帧大小的内容后 + * 会回调录制的文件内容,不指定则不会回调。暂仅支持 mp3 格式。 + */ + frameSize: number; + } + interface OnRecorderManagerStopOptions { + tempFilePath: string; + } + interface OnFrameRecordedOptions { + /** 录音分片结果数据 */ + frameBuffer: ArrayBuffer; + /** 当前帧是否正常录音结束前的最后一帧 */ + isLastFrame: boolean; + } + interface RecorderManager { + /** 开始录音 */ + start(options?: RecorderManagerStartOptions): void; + /** 暂停录音 */ + pause(): void; + /** 继续录音 */ + resume(): void; + /** 停止录音 */ + stop(): void; + /** 录音开始事件 */ + onStart(callback?: () => void): void; + /** 录音暂停事件 */ + onPause(callback?: () => void): void; + /** 录音恢复事件 */ + onResume(callback?: () => void): void; + /** 录音停止事件,会回调文件地址 */ + onStop( + callback?: (options: OnRecorderManagerStopOptions) => void + ): void; + /** 已录制完指定帧大小的文件,会回调录音分片结果数据。如果设置了 frameSize ,则会回调此事件 */ + onFrameRecorded( + callback?: (options: OnFrameRecordedOptions) => void + ): void; + /** 录音错误事件, 会回调错误信息 */ + onError(callback?: (err: ErrMsgResponse) => void): void; + } + /** + * 获取全局唯一的录音管理器 recorderManager + * @version 1.6.0 + */ + function getRecorderManager(): RecorderManager; + // 媒体-----音频播放控制 + interface PlayVoiceOptions extends BaseOptions { + /** 需要播放的语音文件的文件路径 */ + filePath: string; + } + /** + * 开始播放语音,同时只允许一个语音文件正在播放, + * 如果前一个语音文件还没播放完,将中断前一个语音播放。 + * @deprecated 1.6.0 + */ + function playVoice(options: PlayVoiceOptions): void; + /** + * 暂停正在播放的语音。 + * 再次调用wx.playVoice播放同一个文件时,会从暂停处开始播放。 + * 如果想从头开始播放,需要先调用 wx.stopVoice。 + * @deprecated 1.6.0 + */ + function pauseVoice(): void; + /** + * 结束播放语音。 + * @deprecated 1.6.0 + */ + function stopVoice(): void; + // 媒体-----音乐播放控制 + interface BackgroundAudioPlayerState { + /** 选定音频的长度(单位:s),只有在当前有音乐播放时返回 */ + duration: number; + /** 选定音频的播放位置(单位:s),只有在当前有音乐播放时返回 */ + currentPosition: number; + /** 播放状态(2:没有音乐在播放,1:播放中,0:暂停中) */ + status: number; + /** 音频的下载进度(整数,80 代表 80%),只有在当前有音乐播放时返回 */ + downloadPercent: number; + /** 歌曲数据链接,只有在当前有音乐播放时返回 */ + dataUrl: string; + } + interface GetBackgroundAudioPlayerStateOptions extends BaseOptions { + /** 接口调用成功的回调函数 */ + success?(state: BackgroundAudioPlayerState): void; + /** 接口调用失败的回调函数 */ + fail?(): void; + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?(): void; + } + /** + * 获取音乐播放状态。 + * @deprecated 1.2.0 + */ + function getBackgroundAudioPlayerState( + options: GetBackgroundAudioPlayerStateOptions + ): void; + interface PlayBackgroundAudioOptions extends BaseOptions { + /** 音乐链接 */ + dataUrl: string; + /** 音乐标题 */ + title?: string; + /** 封面URL */ + coverImgUrl?: string; + } + /** + * 播放音乐,同时只能有一首音乐正在播放。 + * @deprecated 1.2.0 + */ + function playBackgroundAudio(options: PlayBackgroundAudioOptions): void; + /** + * 暂停播放音乐。 + * @deprecated 1.2.0 + */ + function pauseBackgroundAudio(options?: PlayBackgroundAudioOptions): void; + interface SeekBackgroundAudioOptions extends BaseOptions { + /** 音乐位置,单位:秒 */ + position: number; + } + /** + * 控制音乐播放进度。 + * @deprecated 1.2.0 + */ + function seekBackgroundAudio(options: SeekBackgroundAudioOptions): void; + /** + * 停止播放音乐。 + * @deprecated 1.2.0 + */ + function stopBackgroundAudio(options?: PlayBackgroundAudioOptions): void; + /** + * 监听音乐播放。 + * @deprecated 1.2.0 + */ + function onBackgroundAudioPlay(callback: () => void): void; + /** + * 监听音乐暂停。 + * @deprecated 1.2.0 + */ + function onBackgroundAudioPause(callback: () => void): void; + /** + * 监听音乐停止。 + * @deprecated 1.2.0 + */ + function onBackgroundAudioStop(callback: () => void): void; + interface BackgroundAudioManager { + /** 当前音频的长度(单位:s),只有在当前有合法的 src 时返回 */ + readonly duration: number; + /** 当前音频的播放位置(单位:s),只有在当前有合法的 src 时返回 */ + readonly currentTime: number; + /** 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播放 */ + readonly paused: boolean; + /** 音频的数据源,默认为空字符串,当设置了新的 src 时,会自动开始播放 ,目前支持的格式有 m4a, aac, mp3, wav */ + src: string; + /** 音频开始播放的位置(单位:s) */ + startTime: number; + /** 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲。 是 */ + buffered: number; + /** 音频标题,用于做原生音频播放器音频标题。原生音频播放器中的分享功能,分享出去的卡片标题,也将使用该值。 */ + title: string; + /** 专辑名,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值 */ + epname: string; + /** 歌手名,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值 */ + singer: string; + /** 封面图url,用于做原生音频播放器背景图。原生音频播放器中的分享功能,分享出去的卡片配图及背景也将使用该图。 */ + coverImgUrl: string; + /** 页面链接,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值 */ + webUrl: string; + /** 播放 */ + play(): void; + /** 暂停 */ + pause(): void; + /** 停止 */ + stop(): void; + /** 跳转到指定位置,单位 s */ + seek(position: number): void; + /** 背景音频进入可以播放状态,但不保证后面可以流畅播放 */ + onCanplay(callback?: () => void): void; + /** 背景音频播放事件 */ + onPlay(callback?: () => void): void; + /** 背景音频暂停事件 */ + onPause(callback?: () => void): void; + /** 背景音频停止事件 */ + onStop(callback?: () => void): void; + /** 背景音频自然播放结束事件 */ + onEnded(callback?: () => void): void; + /** 背景音频播放进度更新事件 */ + onTimeUpdate(callback?: () => void): void; + /** 用户在系统音乐播放面板点击上一曲事件(iOS only) */ + onPrev(callback?: () => void): void; + /** 用户在系统音乐播放面板点击下一曲事件(iOS only) */ + onNext(callback?: () => void): void; + /** 背景音频播放错误事件 */ + onError(callback?: () => void): void; + /** 音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 */ + onWaiting(callback?: () => void): void; + } + /** + * 获取全局唯一的背景音频管理器 backgroundAudioManager。 + * @version 1.2.0 + */ + function getBackgroundAudioManager(): BackgroundAudioManager; + // 媒体-----音频组件控制 + /** + * audioContext 通过 audioId 跟一个