From edfc6f5fe954b938bc4b0b95d8deebf99e4c4849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E4=BA=91=E9=BE=99?= Date: Thu, 1 Aug 2019 09:42:04 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=A8FC=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B,=E6=96=B0=E5=A2=9ESFC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/types/index.d.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index b8722f84c24d..aa202c46d289 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -360,9 +360,18 @@ declare namespace Taro { interface FunctionComponent

{ (props: Readonly

): JSX.Element defaultProps?: Partial

+ config?: Config options?: ComponentOptions } + type FC

= FunctionComponent

+ + interface StatelessFunctionComponent { + (): JSX.Element + } + + type SFC = StatelessFunctionComponent + interface ComponentClass

extends StaticLifecycle { new (...args: any[]): Component propTypes?: any From efc6535be3d86a1649d86db5b5514ce4125afba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E4=BA=91=E9=BE=99?= Date: Thu, 1 Aug 2019 09:46:44 +0800 Subject: [PATCH 2/4] =?UTF-8?q?chore(lint):=20=E6=A0=BC=E5=BC=8F=E5=8C=96t?= =?UTF-8?q?aro/types/index.d.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/types/index.d.ts | 523 ++++++++++++++++++--------------- 1 file changed, 283 insertions(+), 240 deletions(-) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index aa202c46d289..0294e2f217e9 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -3,207 +3,205 @@ export = Taro export as namespace Taro declare namespace Taro { - // React Hooks - // ---------------------------------------------------------------------- + // React Hooks + // ---------------------------------------------------------------------- - // based on the code in https://github.com/facebook/react/pull/13968 + // based on the code in https://github.com/facebook/react/pull/13968 - // Unlike the class component setState, the updates are not allowed to be partial - type SetStateAction = S | ((prevState: S) => S) - // this technically does accept a second argument, but it's already under a deprecation warning - // and it's not even released so probably better to not define it. - type Dispatch = (value: A) => void - // Unlike redux, the actions _can_ be anything - type Reducer = (prevState: S, action: A) => S - // types used to try and prevent the compiler from reducing S - // to a supertype common with the second argument to useReducer() - type ReducerState> = R extends Reducer ? S : never - type ReducerAction> = R extends Reducer ? A : never - // The identity check is done with the SameValue algorithm (Object.is), which is stricter than === - // TODO (TypeScript 3.0): ReadonlyArray - type DependencyList = ReadonlyArray + // Unlike the class component setState, the updates are not allowed to be partial + type SetStateAction = S | ((prevState: S) => S) + // this technically does accept a second argument, but it's already under a deprecation warning + // and it's not even released so probably better to not define it. + type Dispatch = (value: A) => void + // Unlike redux, the actions _can_ be anything + type Reducer = (prevState: S, action: A) => S + // types used to try and prevent the compiler from reducing S + // to a supertype common with the second argument to useReducer() + type ReducerState> = R extends Reducer ? S : never + type ReducerAction> = R extends Reducer ? A : never + // The identity check is done with the SameValue algorithm (Object.is), which is stricter than === + // TODO (TypeScript 3.0): ReadonlyArray + type DependencyList = ReadonlyArray - // NOTE: callbacks are _only_ allowed to return either void, or a destructor. - // The destructor is itself only allowed to return void. - type EffectCallback = () => (void | (() => void | undefined)) + // NOTE: callbacks are _only_ allowed to return either void, or a destructor. + // The destructor is itself only allowed to return void. + type EffectCallback = () => void | (() => void | undefined) - interface MutableRefObject { - current: T - } + interface MutableRefObject { + current: T + } - /** - * Returns a stateful value, and a function to update it. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usestate - */ - function useState (initialState: S | (() => S)): [S, Dispatch>] - // convenience overload when first argument is ommitted - /** - * Returns a stateful value, and a function to update it. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usestate - */ - function useState (): [S | undefined, Dispatch>] - /** - * An alternative to `useState`. - * - * `useReducer` is usually preferable to `useState` when you have complex state logic that involves - * multiple sub-values. It also lets you optimize performance for components that trigger deep - * updates because you can pass `dispatch` down instead of callbacks. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usereducer - */ - // overload where "I" may be a subset of ReducerState; used to provide autocompletion. - // If "I" matches ReducerState exactly then the last overload will allow initializer to be ommitted. - // the last overload effectively behaves as if the identity function (x => x) is the initializer. - function useReducer, I> ( - reducer: R, - initializerArg: I & ReducerState, - initializer: (arg: I & ReducerState) => ReducerState - ): [ReducerState, Dispatch>] - /** - * An alternative to `useState`. - * - * `useReducer` is usually preferable to `useState` when you have complex state logic that involves - * multiple sub-values. It also lets you optimize performance for components that trigger deep - * updates because you can pass `dispatch` down instead of callbacks. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usereducer - */ - // overload for free "I"; all goes as long as initializer converts it into "ReducerState". - function useReducer, I> ( - reducer: R, - initializerArg: I, - initializer: (arg: I) => ReducerState - ): [ReducerState, Dispatch>] - /** - * An alternative to `useState`. - * - * `useReducer` is usually preferable to `useState` when you have complex state logic that involves - * multiple sub-values. It also lets you optimize performance for components that trigger deep - * updates because you can pass `dispatch` down instead of callbacks. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usereducer - */ + /** + * Returns a stateful value, and a function to update it. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usestate + */ + function useState(initialState: S | (() => S)): [S, Dispatch>] + // convenience overload when first argument is ommitted + /** + * Returns a stateful value, and a function to update it. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usestate + */ + function useState(): [S | undefined, Dispatch>] + /** + * An alternative to `useState`. + * + * `useReducer` is usually preferable to `useState` when you have complex state logic that involves + * multiple sub-values. It also lets you optimize performance for components that trigger deep + * updates because you can pass `dispatch` down instead of callbacks. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usereducer + */ + // overload where "I" may be a subset of ReducerState; used to provide autocompletion. + // If "I" matches ReducerState exactly then the last overload will allow initializer to be ommitted. + // the last overload effectively behaves as if the identity function (x => x) is the initializer. + function useReducer, I>( + reducer: R, + initializerArg: I & ReducerState, + initializer: (arg: I & ReducerState) => ReducerState + ): [ReducerState, Dispatch>] + /** + * An alternative to `useState`. + * + * `useReducer` is usually preferable to `useState` when you have complex state logic that involves + * multiple sub-values. It also lets you optimize performance for components that trigger deep + * updates because you can pass `dispatch` down instead of callbacks. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usereducer + */ + // overload for free "I"; all goes as long as initializer converts it into "ReducerState". + function useReducer, I>( + reducer: R, + initializerArg: I, + initializer: (arg: I) => ReducerState + ): [ReducerState, Dispatch>] + /** + * An alternative to `useState`. + * + * `useReducer` is usually preferable to `useState` when you have complex state logic that involves + * multiple sub-values. It also lets you optimize performance for components that trigger deep + * updates because you can pass `dispatch` down instead of callbacks. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usereducer + */ - // I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary. - // The Flow types do have an overload for 3-ary invocation with undefined initializer. + // I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary. + // The Flow types do have an overload for 3-ary invocation with undefined initializer. - // NOTE: without the ReducerState indirection, TypeScript would reduce S to be the most common - // supertype between the reducer's return type and the initialState (or the initializer's return type), - // which would prevent autocompletion from ever working. + // NOTE: without the ReducerState indirection, TypeScript would reduce S to be the most common + // supertype between the reducer's return type and the initialState (or the initializer's return type), + // which would prevent autocompletion from ever working. - // TODO: double-check if this weird overload logic is necessary. It is possible it's either a bug - // in older versions, or a regression in newer versions of the typescript completion service. - function useReducer> ( - reducer: R, - initialState: ReducerState, - initializer?: undefined - ): [ReducerState, Dispatch>] - /** - * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument - * (`initialValue`). The returned object will persist for the full lifetime of the component. - * - * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable - * value around similar to how you’d use instance fields in classes. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useref - */ - // TODO (TypeScript 3.0): - function useRef (initialValue: T): MutableRefObject + // TODO: double-check if this weird overload logic is necessary. It is possible it's either a bug + // in older versions, or a regression in newer versions of the typescript completion service. + function useReducer>( + reducer: R, + initialState: ReducerState, + initializer?: undefined + ): [ReducerState, Dispatch>] + /** + * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument + * (`initialValue`). The returned object will persist for the full lifetime of the component. + * + * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable + * value around similar to how you’d use instance fields in classes. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useref + */ + // TODO (TypeScript 3.0): + function useRef(initialValue: T): MutableRefObject - interface RefObject { - readonly current: T | null - } + interface RefObject { + readonly current: T | null + } - function createRef(): RefObject; + function createRef(): RefObject - // convenience overload for refs given as a ref prop as they typically start with a null value - /** - * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument - * (`initialValue`). The returned object will persist for the full lifetime of the component. - * - * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable - * value around similar to how you’d use instance fields in classes. - * - * Usage note: if you need the result of useRef to be directly mutable, include `| null` in the type - * of the generic argument. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useref - */ - // TODO (TypeScript 3.0): - function useRef (initialValue: T | null): RefObject - // convenience overload for potentially undefined initialValue / call with 0 arguments - // has a default to stop it from defaulting to {} instead - /** - * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument - * (`initialValue`). The returned object will persist for the full lifetime of the component. - * - * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable - * value around similar to how you’d use instance fields in classes. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useref - */ - // TODO (TypeScript 3.0): - function useRef (): MutableRefObject - /** - * The signature is identical to `useEffect`, but it fires synchronously after all DOM mutations. - * Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside - * `useLayoutEffect` will be flushed synchronously, before the browser has a chance to paint. - * - * Prefer the standard `useEffect` when possible to avoid blocking visual updates. - * - * If you’re migrating code from a class component, `useLayoutEffect` fires in the same phase as - * `componentDidMount` and `componentDidUpdate`. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect - */ - function useLayoutEffect (effect: EffectCallback, deps?: DependencyList): void - /** - * Accepts a function that contains imperative, possibly effectful code. - * - * @param effect Imperative function that can return a cleanup function - * @param deps If present, effect will only activate if the values in the list change. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useeffect - */ - function useEffect (effect: EffectCallback, deps?: DependencyList): void - // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref - /** - * `useImperativeHandle` customizes the instance value that is exposed to parent components when using - * `ref`. As always, imperative code using refs should be avoided in most cases. - * - * `useImperativeHandle` should be used with `React.forwardRef`. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle - */ - type Ref = - | string - | { bivarianceHack (instance: T | null): any }['bivarianceHack'] - function useImperativeHandle (ref: Ref | undefined, init: () => R, deps?: DependencyList): void - // I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key - // useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y. - /** - * `useCallback` will return a memoized version of the callback that only changes if one of the `inputs` - * has changed. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usecallback - */ - // TODO (TypeScript 3.0): unknown> - function useCallback any> (callback: T, deps: DependencyList): T - /** + // convenience overload for refs given as a ref prop as they typically start with a null value + /** + * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument + * (`initialValue`). The returned object will persist for the full lifetime of the component. + * + * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable + * value around similar to how you’d use instance fields in classes. + * + * Usage note: if you need the result of useRef to be directly mutable, include `| null` in the type + * of the generic argument. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useref + */ + // TODO (TypeScript 3.0): + function useRef(initialValue: T | null): RefObject + // convenience overload for potentially undefined initialValue / call with 0 arguments + // has a default to stop it from defaulting to {} instead + /** + * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument + * (`initialValue`). The returned object will persist for the full lifetime of the component. + * + * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable + * value around similar to how you’d use instance fields in classes. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useref + */ + // TODO (TypeScript 3.0): + function useRef(): MutableRefObject + /** + * The signature is identical to `useEffect`, but it fires synchronously after all DOM mutations. + * Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside + * `useLayoutEffect` will be flushed synchronously, before the browser has a chance to paint. + * + * Prefer the standard `useEffect` when possible to avoid blocking visual updates. + * + * If you’re migrating code from a class component, `useLayoutEffect` fires in the same phase as + * `componentDidMount` and `componentDidUpdate`. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect + */ + function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void + /** + * Accepts a function that contains imperative, possibly effectful code. + * + * @param effect Imperative function that can return a cleanup function + * @param deps If present, effect will only activate if the values in the list change. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useeffect + */ + function useEffect(effect: EffectCallback, deps?: DependencyList): void + // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref + /** + * `useImperativeHandle` customizes the instance value that is exposed to parent components when using + * `ref`. As always, imperative code using refs should be avoided in most cases. + * + * `useImperativeHandle` should be used with `React.forwardRef`. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle + */ + type Ref = string | { bivarianceHack(instance: T | null): any }['bivarianceHack'] + function useImperativeHandle(ref: Ref | undefined, init: () => R, deps?: DependencyList): void + // I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key + // useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y. + /** + * `useCallback` will return a memoized version of the callback that only changes if one of the `inputs` + * has changed. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usecallback + */ + // TODO (TypeScript 3.0): unknown> + function useCallback any>(callback: T, deps: DependencyList): T + /** * `useMemo` will only recompute the memoized value when one of the `deps` has changed. * * Usage note: if calling `useMemo` with a referentially stable function, also give it as the input in @@ -221,8 +219,8 @@ declare namespace Taro { * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usememo */ - // allow undefined, but don't make it optional as that is very likely a mistake - function useMemo (factory: () => T, deps: DependencyList | undefined): T + // allow undefined, but don't make it optional as that is very likely a mistake + function useMemo(factory: () => T, deps: DependencyList | undefined): T interface PageNotFoundObject { /** * 不存在页面的路径 @@ -299,15 +297,15 @@ declare namespace Taro { } type GetDerivedStateFromProps = - /** - * Returns an update to a component's state based on its new props and old state. - * - * Note: its presence prevents any of the deprecated lifecycle methods from being invoked - */ - (nextProps: Readonly

, prevState: S) => Partial | null; + /** + * Returns an update to a component's state based on its new props and old state. + * + * Note: its presence prevents any of the deprecated lifecycle methods from being invoked + */ + (nextProps: Readonly

, prevState: S) => Partial | null interface StaticLifecycle { - getDerivedStateFromProps?: GetDerivedStateFromProps; + getDerivedStateFromProps?: GetDerivedStateFromProps } interface NewLifecycle { @@ -319,14 +317,14 @@ declare namespace Taro { * Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated * lifecycle events from running. */ - getSnapshotBeforeUpdate?(prevProps: Readonly

, prevState: Readonly): SS | null; + getSnapshotBeforeUpdate?(prevProps: Readonly

, prevState: Readonly): SS | null /** * Called immediately after updating occurs. Not called for the initial render. * * The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null. */ - componentDidUpdate?(prevProps: Readonly

, prevState: Readonly, snapshot?: SS): void; -} + componentDidUpdate?(prevProps: Readonly

, prevState: Readonly, snapshot?: SS): void + } // Components interface ComponentLifecycle extends NewLifecycle { @@ -384,14 +382,11 @@ declare namespace Taro { // type Provider = ProviderExoticComponent>; // type Consumer = ExoticComponent>; interface Context { - Provider: ComponentClass<{ value: T }>; - // Consumer: Consumer; - displayName?: string; + Provider: ComponentClass<{ value: T }> + // Consumer: Consumer; + displayName?: string } - function createContext( - defaultValue: T - ): Context; - + function createContext(defaultValue: T): Context // This will technically work if you give a Consumer or Provider but it's deprecated and warns /** @@ -401,8 +396,7 @@ declare namespace Taro { * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usecontext */ - function useContext(context: Context/*, (not public API) observedBits?: number|boolean */): T; - + function useContext(context: Context /*, (not public API) observedBits?: number|boolean */): T /** * 微信小程序全局 Window 配置和页面配置的公共项目 @@ -729,9 +723,9 @@ declare namespace Taro { } & { path?: string scene?: number | string - query?: {[key: string]: string} | string + query?: { [key: string]: string } | string shareTicket?: string - referrerInfo?: {[key: string]: any} | string + referrerInfo?: { [key: string]: any } | string } /** * 可以于 `this.$router.preload` 中访问到 `this.$preload` 传入的参数 @@ -765,7 +759,10 @@ declare namespace Taro { $preload(key: string, value: any): void $preload(key: object): void - setState(state: ((prevState: Readonly, props: P) => Pick | S) | (Pick | S), callback?: () => any): void + setState( + state: ((prevState: Readonly, props: P) => Pick | S) | (Pick | S), + callback?: () => any + ): void forceUpdate(callBack?: () => any): void @@ -895,7 +892,7 @@ declare namespace Taro { */ namespace request { - type Promised < T extends any | string | ArrayBuffer = any > = { + type Promised = { /** * 开发者服务器返回的数据 * @@ -930,7 +927,7 @@ declare namespace Taro { */ abort(): void } - type Param < P extends any | string | ArrayBuffer = any > = { + type Param

= { /** * 开发者服务器接口地址 */ @@ -1121,7 +1118,18 @@ declare namespace Taro { */ function request(OBJECT: request.Param): request.requestTask - type arrayBuffer = Uint8Array | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | ArrayBuffer + type arrayBuffer = + | Uint8Array + | Int8Array + | Uint8Array + | Uint8ClampedArray + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + | Float32Array + | Float64Array + | ArrayBuffer /** * 将 ArrayBuffer 数据转成 Base64 字符串 @@ -1539,8 +1547,8 @@ declare namespace Taro { function sendSocketMessage(OBJECT: sendSocketMessage.Param): Promise namespace onSocketMessage { - type Param < T = any > = (res: ParamParam) => any - type ParamParam < T extends any | string | ArrayBuffer = any > = { + type Param = (res: ParamParam) => any + type ParamParam = { /** * 服务器返回的消息 */ @@ -1698,8 +1706,8 @@ declare namespace Taro { } } namespace onMessage { - type Param < T = any > = (res: ParamParam) => any - type ParamParam < T extends any | string | ArrayBuffer = any > = { + type Param = (res: ParamParam) => any + type ParamParam = { /** * 服务器返回的消息 */ @@ -1713,7 +1721,6 @@ declare namespace Taro { * WebSocket 任务,可通过 [Taro.connectSocket()](https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.html) 接口创建返回。 */ class SocketTask { - /** * websocket 当前的连接 ID。 */ @@ -1932,7 +1939,15 @@ declare namespace Taro { * * @since 1.9.90 */ - orientation: 'up' | 'down' | 'left' | 'right' | 'up-mirrored' | 'down-mirrored ' | 'left-mirrored' | 'right-mirrored' + orientation: + | 'up' + | 'down' + | 'left' + | 'right' + | 'up-mirrored' + | 'down-mirrored ' + | 'left-mirrored' + | 'right-mirrored' /** * 返回图片的格式 * @@ -2468,7 +2483,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.getBackgroundAudioPlayerState.html */ - function getBackgroundAudioPlayerState(OBJECT?: getBackgroundAudioPlayerState.Param): Promise + function getBackgroundAudioPlayerState( + OBJECT?: getBackgroundAudioPlayerState.Param + ): Promise namespace playBackgroundAudio { type Param = { @@ -5456,7 +5473,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.startBluetoothDevicesDiscovery.html */ - function startBluetoothDevicesDiscovery(OBJECT?: startBluetoothDevicesDiscovery.Param): Promise + function startBluetoothDevicesDiscovery( + OBJECT?: startBluetoothDevicesDiscovery.Param + ): Promise namespace stopBluetoothDevicesDiscovery { type Promised = { @@ -5483,7 +5502,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.stopBluetoothDevicesDiscovery.html */ - function stopBluetoothDevicesDiscovery(OBJECT?: stopBluetoothDevicesDiscovery.Param): Promise + function stopBluetoothDevicesDiscovery( + OBJECT?: stopBluetoothDevicesDiscovery.Param + ): Promise namespace getBluetoothDevices { type Promised = { @@ -5699,7 +5720,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.getConnectedBluetoothDevices.html */ - function getConnectedBluetoothDevices(OBJECT: getConnectedBluetoothDevices.Param): Promise + function getConnectedBluetoothDevices( + OBJECT: getConnectedBluetoothDevices.Param + ): Promise namespace createBLEConnection { type Promised = { @@ -5944,7 +5967,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceCharacteristics.html */ - function getBLEDeviceCharacteristics(OBJECT: getBLEDeviceCharacteristics.Param): Promise + function getBLEDeviceCharacteristics( + OBJECT: getBLEDeviceCharacteristics.Param + ): Promise namespace readBLECharacteristicValue { type Promised = { @@ -6003,7 +6028,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.readBLECharacteristicValue.html */ - function readBLECharacteristicValue(OBJECT: readBLECharacteristicValue.Param): Promise + function readBLECharacteristicValue( + OBJECT: readBLECharacteristicValue.Param + ): Promise namespace writeBLECharacteristicValue { type Promised = { @@ -6068,7 +6095,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.writeBLECharacteristicValue.html */ - function writeBLECharacteristicValue(OBJECT: writeBLECharacteristicValue.Param): Promise + function writeBLECharacteristicValue( + OBJECT: writeBLECharacteristicValue.Param + ): Promise namespace notifyBLECharacteristicValueChange { type Promised = { @@ -6126,7 +6155,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.notifyBLECharacteristicValueChange.html */ - function notifyBLECharacteristicValueChange(OBJECT: notifyBLECharacteristicValueChange.Param): Promise + function notifyBLECharacteristicValueChange( + OBJECT: notifyBLECharacteristicValueChange.Param + ): Promise namespace onBLECharacteristicValueChange { type Param = (res: ParamParam) => any @@ -9085,7 +9116,9 @@ declare namespace Taro { checkAliveType?: number } } - function checkIsSupportFacialRecognition(OBJECT?: checkIsSupportFacialRecognition.Param): Promise + function checkIsSupportFacialRecognition( + OBJECT?: checkIsSupportFacialRecognition.Param + ): Promise namespace startFacialRecognitionVerify { type Promised = { @@ -9099,7 +9132,9 @@ declare namespace Taro { checkAliveType?: number } } - function startFacialRecognitionVerify(OBJECT?: startFacialRecognitionVerify.Param): Promise + function startFacialRecognitionVerify( + OBJECT?: startFacialRecognitionVerify.Param + ): Promise namespace startFacialRecognitionVerifyAndUploadVideo { type Promised = { @@ -9113,7 +9148,9 @@ declare namespace Taro { checkAliveType?: number } } - function startFacialRecognitionVerifyAndUploadVideo(OBJECT?: startFacialRecognitionVerifyAndUploadVideo.Param): Promise + function startFacialRecognitionVerifyAndUploadVideo( + OBJECT?: startFacialRecognitionVerifyAndUploadVideo.Param + ): Promise namespace requestPayment { type Param = { @@ -9880,7 +9917,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/soter/wx.checkIsSupportSoterAuthentication.html */ - function checkIsSupportSoterAuthentication(OBJECT?: checkIsSupportSoterAuthentication.Param): Promise + function checkIsSupportSoterAuthentication( + OBJECT?: checkIsSupportSoterAuthentication.Param + ): Promise namespace startSoterAuthentication { type Promised = { @@ -10023,7 +10062,9 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/soter/wx.checkIsSoterEnrolledInDevice.html */ - function checkIsSoterEnrolledInDevice(OBJECT: checkIsSoterEnrolledInDevice.Param): Promise + function checkIsSoterEnrolledInDevice( + OBJECT: checkIsSoterEnrolledInDevice.Param + ): Promise /** * @since 2.0.1 @@ -10279,7 +10320,9 @@ declare namespace Taro { getContext(contextType: string): any } namespace CanvasContext { - namespace draw { type Param1 = () => any } + namespace draw { + type Param1 = () => any + } } interface Color {} @@ -11611,7 +11654,7 @@ declare namespace Taro { /** * 来源信息。从另一个小程序、公众号或 App 进入小程序时返回。否则返回 {}。 */ - referrerInfo: { appId: string, extraData: { [k: string]: any} } + referrerInfo: { appId: string; extraData: { [k: string]: any } } } } @@ -11636,11 +11679,11 @@ declare namespace Taro { /** * 不存在页面的路径 */ - path: string, + path: string /** * 打开不存在页面的 query 参数 */ - query: Object, + query: Object /** * 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */ From 324f2cb704ed39b7f27d420368a255b81b1f1d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E4=BA=91=E9=BE=99?= Date: Thu, 1 Aug 2019 10:24:00 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=99=BE?= =?UTF-8?q?=E5=BA=A6setPageInfo=E7=9A=84API=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/types/index.d.ts | 114 +++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index 0294e2f217e9..089d2efb56f3 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -11733,6 +11733,120 @@ declare namespace Taro { */ function onAudioInterruptionBegin(callback: () => void): void + namespace setPageInfo { + type Param = { + /** + * 页面标题 + */ + title: string + /** + * 页面关键字 + */ + keywords: string + /** + * 页面描述信息 + */ + description: string + /** + * 原始发布时间(年-月-日 时:分:秒 带有前导零) + */ + releaseDate?: string + /** + * 文章(内容)标题(适用于当前页面是图文、视频类的展示形式,文章标题需要准确标识当前文章的主要信息点;至少6个字,不可以全英文。) + */ + articleTitle?: string + /** + * 图片线上地址,用于信息流投放后的封面显示,最多3张,单图片最大2M;封面图建议尺寸:高>=210px & 宽>=375px;最小尺寸:高>=146px & 宽>=218px。多张图时,用数组表示 + */ + image?: string | Array + /** + * 视频信息,多个视频时,用数组表示 + */ + video?: Video + /** + * 浏览信息。最低支持版本3.40.6。 + */ + visit?: Visit + /** + * 点赞量,若页面未统计可为空。最低支持版本3.40.6。 + */ + likes?: string + /** + * 评论量,若页面未统计可为空。最低支持版本3.40.6。 + */ + comments?: string + /** + * 收藏量,若页面未统计可为空。最低支持版本3.40.6。 + */ + collects?: string + /** + * 分享量,若页面未统计可为空。最低支持版本3.40.6。 + */ + shares?: string + /** + * 关注量,若页面未统计可为空。最低支持版本3.40.6。 + */ + followers?: string + /** + * 接口调用成功的回调函数 + */ + success?: ParamPropSuccess + /** + * 接口调用失败的回调函数 + */ + fail?: ParamPropFail + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + complete?: ParamPropComplete + } + type Video = { + /** + * 视频地址 + */ + url: string + /** + * 视频时长(单位为秒) + */ + duration: string + /** + * 视频封面图 + */ + image: string + } + type Visit = { + /** + * 页面的浏览量(不去重用户) + */ + pv?: string + /** + * 页面的点击量(去重用户) + */ + uv?: string + /** + * 页面的用户人均停留时长,以秒为单位。 + */ + sessionDuration?: string + } + /** + * 接口调用成功的回调函数 + */ + type ParamPropSuccess = () => any + /** + * 接口调用失败的回调函数 + */ + type ParamPropFail = (err: any) => any + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + type ParamPropComplete = () => any + } + + /** + * 百度智能小程序可接入百度搜索和百度 App,setPageInfo 负责为小程序设置各类页面基础信息,包括标题、关键字、页面描述以及图片信息、视频信息等。开发者为智能小程序设置完备的页面基础信息,有助于智能小程序在搜索引擎和信息流中得到更加有效的展示和分发。 + */ + function setPageInfo(OBJECT: setPageInfo.Param): void + namespace cloud { interface ICloudConfig { env?: string | object From 08df4c6348ea1329bad9f2f50734011f1ce5e833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E4=BA=91=E9=BE=99?= Date: Thu, 1 Aug 2019 14:11:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Revert=20"chore(lint):=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96taro/types/index.d.ts"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit efc6535be3d86a1649d86db5b5514ce4125afba2. --- packages/taro/types/index.d.ts | 523 +++++++++++++++------------------ 1 file changed, 240 insertions(+), 283 deletions(-) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index 089d2efb56f3..425670e6bc51 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -3,205 +3,207 @@ export = Taro export as namespace Taro declare namespace Taro { - // React Hooks - // ---------------------------------------------------------------------- + // React Hooks + // ---------------------------------------------------------------------- - // based on the code in https://github.com/facebook/react/pull/13968 + // based on the code in https://github.com/facebook/react/pull/13968 - // Unlike the class component setState, the updates are not allowed to be partial - type SetStateAction = S | ((prevState: S) => S) - // this technically does accept a second argument, but it's already under a deprecation warning - // and it's not even released so probably better to not define it. - type Dispatch = (value: A) => void - // Unlike redux, the actions _can_ be anything - type Reducer = (prevState: S, action: A) => S - // types used to try and prevent the compiler from reducing S - // to a supertype common with the second argument to useReducer() - type ReducerState> = R extends Reducer ? S : never - type ReducerAction> = R extends Reducer ? A : never - // The identity check is done with the SameValue algorithm (Object.is), which is stricter than === - // TODO (TypeScript 3.0): ReadonlyArray - type DependencyList = ReadonlyArray + // Unlike the class component setState, the updates are not allowed to be partial + type SetStateAction = S | ((prevState: S) => S) + // this technically does accept a second argument, but it's already under a deprecation warning + // and it's not even released so probably better to not define it. + type Dispatch = (value: A) => void + // Unlike redux, the actions _can_ be anything + type Reducer = (prevState: S, action: A) => S + // types used to try and prevent the compiler from reducing S + // to a supertype common with the second argument to useReducer() + type ReducerState> = R extends Reducer ? S : never + type ReducerAction> = R extends Reducer ? A : never + // The identity check is done with the SameValue algorithm (Object.is), which is stricter than === + // TODO (TypeScript 3.0): ReadonlyArray + type DependencyList = ReadonlyArray - // NOTE: callbacks are _only_ allowed to return either void, or a destructor. - // The destructor is itself only allowed to return void. - type EffectCallback = () => void | (() => void | undefined) + // NOTE: callbacks are _only_ allowed to return either void, or a destructor. + // The destructor is itself only allowed to return void. + type EffectCallback = () => (void | (() => void | undefined)) - interface MutableRefObject { - current: T - } + interface MutableRefObject { + current: T + } - /** - * Returns a stateful value, and a function to update it. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usestate - */ - function useState(initialState: S | (() => S)): [S, Dispatch>] - // convenience overload when first argument is ommitted - /** - * Returns a stateful value, and a function to update it. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usestate - */ - function useState(): [S | undefined, Dispatch>] - /** - * An alternative to `useState`. - * - * `useReducer` is usually preferable to `useState` when you have complex state logic that involves - * multiple sub-values. It also lets you optimize performance for components that trigger deep - * updates because you can pass `dispatch` down instead of callbacks. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usereducer - */ - // overload where "I" may be a subset of ReducerState; used to provide autocompletion. - // If "I" matches ReducerState exactly then the last overload will allow initializer to be ommitted. - // the last overload effectively behaves as if the identity function (x => x) is the initializer. - function useReducer, I>( - reducer: R, - initializerArg: I & ReducerState, - initializer: (arg: I & ReducerState) => ReducerState - ): [ReducerState, Dispatch>] - /** - * An alternative to `useState`. - * - * `useReducer` is usually preferable to `useState` when you have complex state logic that involves - * multiple sub-values. It also lets you optimize performance for components that trigger deep - * updates because you can pass `dispatch` down instead of callbacks. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usereducer - */ - // overload for free "I"; all goes as long as initializer converts it into "ReducerState". - function useReducer, I>( - reducer: R, - initializerArg: I, - initializer: (arg: I) => ReducerState - ): [ReducerState, Dispatch>] - /** - * An alternative to `useState`. - * - * `useReducer` is usually preferable to `useState` when you have complex state logic that involves - * multiple sub-values. It also lets you optimize performance for components that trigger deep - * updates because you can pass `dispatch` down instead of callbacks. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usereducer - */ + /** + * Returns a stateful value, and a function to update it. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usestate + */ + function useState (initialState: S | (() => S)): [S, Dispatch>] + // convenience overload when first argument is ommitted + /** + * Returns a stateful value, and a function to update it. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usestate + */ + function useState (): [S | undefined, Dispatch>] + /** + * An alternative to `useState`. + * + * `useReducer` is usually preferable to `useState` when you have complex state logic that involves + * multiple sub-values. It also lets you optimize performance for components that trigger deep + * updates because you can pass `dispatch` down instead of callbacks. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usereducer + */ + // overload where "I" may be a subset of ReducerState; used to provide autocompletion. + // If "I" matches ReducerState exactly then the last overload will allow initializer to be ommitted. + // the last overload effectively behaves as if the identity function (x => x) is the initializer. + function useReducer, I> ( + reducer: R, + initializerArg: I & ReducerState, + initializer: (arg: I & ReducerState) => ReducerState + ): [ReducerState, Dispatch>] + /** + * An alternative to `useState`. + * + * `useReducer` is usually preferable to `useState` when you have complex state logic that involves + * multiple sub-values. It also lets you optimize performance for components that trigger deep + * updates because you can pass `dispatch` down instead of callbacks. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usereducer + */ + // overload for free "I"; all goes as long as initializer converts it into "ReducerState". + function useReducer, I> ( + reducer: R, + initializerArg: I, + initializer: (arg: I) => ReducerState + ): [ReducerState, Dispatch>] + /** + * An alternative to `useState`. + * + * `useReducer` is usually preferable to `useState` when you have complex state logic that involves + * multiple sub-values. It also lets you optimize performance for components that trigger deep + * updates because you can pass `dispatch` down instead of callbacks. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usereducer + */ - // I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary. - // The Flow types do have an overload for 3-ary invocation with undefined initializer. + // I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary. + // The Flow types do have an overload for 3-ary invocation with undefined initializer. - // NOTE: without the ReducerState indirection, TypeScript would reduce S to be the most common - // supertype between the reducer's return type and the initialState (or the initializer's return type), - // which would prevent autocompletion from ever working. + // NOTE: without the ReducerState indirection, TypeScript would reduce S to be the most common + // supertype between the reducer's return type and the initialState (or the initializer's return type), + // which would prevent autocompletion from ever working. - // TODO: double-check if this weird overload logic is necessary. It is possible it's either a bug - // in older versions, or a regression in newer versions of the typescript completion service. - function useReducer>( - reducer: R, - initialState: ReducerState, - initializer?: undefined - ): [ReducerState, Dispatch>] - /** - * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument - * (`initialValue`). The returned object will persist for the full lifetime of the component. - * - * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable - * value around similar to how you’d use instance fields in classes. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useref - */ - // TODO (TypeScript 3.0): - function useRef(initialValue: T): MutableRefObject + // TODO: double-check if this weird overload logic is necessary. It is possible it's either a bug + // in older versions, or a regression in newer versions of the typescript completion service. + function useReducer> ( + reducer: R, + initialState: ReducerState, + initializer?: undefined + ): [ReducerState, Dispatch>] + /** + * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument + * (`initialValue`). The returned object will persist for the full lifetime of the component. + * + * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable + * value around similar to how you’d use instance fields in classes. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useref + */ + // TODO (TypeScript 3.0): + function useRef (initialValue: T): MutableRefObject - interface RefObject { - readonly current: T | null - } + interface RefObject { + readonly current: T | null + } - function createRef(): RefObject + function createRef(): RefObject; - // convenience overload for refs given as a ref prop as they typically start with a null value - /** - * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument - * (`initialValue`). The returned object will persist for the full lifetime of the component. - * - * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable - * value around similar to how you’d use instance fields in classes. - * - * Usage note: if you need the result of useRef to be directly mutable, include `| null` in the type - * of the generic argument. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useref - */ - // TODO (TypeScript 3.0): - function useRef(initialValue: T | null): RefObject - // convenience overload for potentially undefined initialValue / call with 0 arguments - // has a default to stop it from defaulting to {} instead - /** - * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument - * (`initialValue`). The returned object will persist for the full lifetime of the component. - * - * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable - * value around similar to how you’d use instance fields in classes. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useref - */ - // TODO (TypeScript 3.0): - function useRef(): MutableRefObject - /** - * The signature is identical to `useEffect`, but it fires synchronously after all DOM mutations. - * Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside - * `useLayoutEffect` will be flushed synchronously, before the browser has a chance to paint. - * - * Prefer the standard `useEffect` when possible to avoid blocking visual updates. - * - * If you’re migrating code from a class component, `useLayoutEffect` fires in the same phase as - * `componentDidMount` and `componentDidUpdate`. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect - */ - function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void - /** - * Accepts a function that contains imperative, possibly effectful code. - * - * @param effect Imperative function that can return a cleanup function - * @param deps If present, effect will only activate if the values in the list change. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useeffect - */ - function useEffect(effect: EffectCallback, deps?: DependencyList): void - // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref - /** - * `useImperativeHandle` customizes the instance value that is exposed to parent components when using - * `ref`. As always, imperative code using refs should be avoided in most cases. - * - * `useImperativeHandle` should be used with `React.forwardRef`. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle - */ - type Ref = string | { bivarianceHack(instance: T | null): any }['bivarianceHack'] - function useImperativeHandle(ref: Ref | undefined, init: () => R, deps?: DependencyList): void - // I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key - // useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y. - /** - * `useCallback` will return a memoized version of the callback that only changes if one of the `inputs` - * has changed. - * - * @version 16.8.0 - * @see https://reactjs.org/docs/hooks-reference.html#usecallback - */ - // TODO (TypeScript 3.0): unknown> - function useCallback any>(callback: T, deps: DependencyList): T - /** + // convenience overload for refs given as a ref prop as they typically start with a null value + /** + * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument + * (`initialValue`). The returned object will persist for the full lifetime of the component. + * + * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable + * value around similar to how you’d use instance fields in classes. + * + * Usage note: if you need the result of useRef to be directly mutable, include `| null` in the type + * of the generic argument. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useref + */ + // TODO (TypeScript 3.0): + function useRef (initialValue: T | null): RefObject + // convenience overload for potentially undefined initialValue / call with 0 arguments + // has a default to stop it from defaulting to {} instead + /** + * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument + * (`initialValue`). The returned object will persist for the full lifetime of the component. + * + * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable + * value around similar to how you’d use instance fields in classes. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useref + */ + // TODO (TypeScript 3.0): + function useRef (): MutableRefObject + /** + * The signature is identical to `useEffect`, but it fires synchronously after all DOM mutations. + * Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside + * `useLayoutEffect` will be flushed synchronously, before the browser has a chance to paint. + * + * Prefer the standard `useEffect` when possible to avoid blocking visual updates. + * + * If you’re migrating code from a class component, `useLayoutEffect` fires in the same phase as + * `componentDidMount` and `componentDidUpdate`. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect + */ + function useLayoutEffect (effect: EffectCallback, deps?: DependencyList): void + /** + * Accepts a function that contains imperative, possibly effectful code. + * + * @param effect Imperative function that can return a cleanup function + * @param deps If present, effect will only activate if the values in the list change. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useeffect + */ + function useEffect (effect: EffectCallback, deps?: DependencyList): void + // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref + /** + * `useImperativeHandle` customizes the instance value that is exposed to parent components when using + * `ref`. As always, imperative code using refs should be avoided in most cases. + * + * `useImperativeHandle` should be used with `React.forwardRef`. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle + */ + type Ref = + | string + | { bivarianceHack (instance: T | null): any }['bivarianceHack'] + function useImperativeHandle (ref: Ref | undefined, init: () => R, deps?: DependencyList): void + // I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key + // useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y. + /** + * `useCallback` will return a memoized version of the callback that only changes if one of the `inputs` + * has changed. + * + * @version 16.8.0 + * @see https://reactjs.org/docs/hooks-reference.html#usecallback + */ + // TODO (TypeScript 3.0): unknown> + function useCallback any> (callback: T, deps: DependencyList): T + /** * `useMemo` will only recompute the memoized value when one of the `deps` has changed. * * Usage note: if calling `useMemo` with a referentially stable function, also give it as the input in @@ -219,8 +221,8 @@ declare namespace Taro { * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usememo */ - // allow undefined, but don't make it optional as that is very likely a mistake - function useMemo(factory: () => T, deps: DependencyList | undefined): T + // allow undefined, but don't make it optional as that is very likely a mistake + function useMemo (factory: () => T, deps: DependencyList | undefined): T interface PageNotFoundObject { /** * 不存在页面的路径 @@ -297,15 +299,15 @@ declare namespace Taro { } type GetDerivedStateFromProps = - /** - * Returns an update to a component's state based on its new props and old state. - * - * Note: its presence prevents any of the deprecated lifecycle methods from being invoked - */ - (nextProps: Readonly

, prevState: S) => Partial | null + /** + * Returns an update to a component's state based on its new props and old state. + * + * Note: its presence prevents any of the deprecated lifecycle methods from being invoked + */ + (nextProps: Readonly

, prevState: S) => Partial | null; interface StaticLifecycle { - getDerivedStateFromProps?: GetDerivedStateFromProps + getDerivedStateFromProps?: GetDerivedStateFromProps; } interface NewLifecycle { @@ -317,14 +319,14 @@ declare namespace Taro { * Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated * lifecycle events from running. */ - getSnapshotBeforeUpdate?(prevProps: Readonly

, prevState: Readonly): SS | null + getSnapshotBeforeUpdate?(prevProps: Readonly

, prevState: Readonly): SS | null; /** * Called immediately after updating occurs. Not called for the initial render. * * The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null. */ - componentDidUpdate?(prevProps: Readonly

, prevState: Readonly, snapshot?: SS): void - } + componentDidUpdate?(prevProps: Readonly

, prevState: Readonly, snapshot?: SS): void; +} // Components interface ComponentLifecycle extends NewLifecycle { @@ -382,11 +384,14 @@ declare namespace Taro { // type Provider = ProviderExoticComponent>; // type Consumer = ExoticComponent>; interface Context { - Provider: ComponentClass<{ value: T }> - // Consumer: Consumer; - displayName?: string + Provider: ComponentClass<{ value: T }>; + // Consumer: Consumer; + displayName?: string; } - function createContext(defaultValue: T): Context + function createContext( + defaultValue: T + ): Context; + // This will technically work if you give a Consumer or Provider but it's deprecated and warns /** @@ -396,7 +401,8 @@ declare namespace Taro { * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usecontext */ - function useContext(context: Context /*, (not public API) observedBits?: number|boolean */): T + function useContext(context: Context/*, (not public API) observedBits?: number|boolean */): T; + /** * 微信小程序全局 Window 配置和页面配置的公共项目 @@ -723,9 +729,9 @@ declare namespace Taro { } & { path?: string scene?: number | string - query?: { [key: string]: string } | string + query?: {[key: string]: string} | string shareTicket?: string - referrerInfo?: { [key: string]: any } | string + referrerInfo?: {[key: string]: any} | string } /** * 可以于 `this.$router.preload` 中访问到 `this.$preload` 传入的参数 @@ -759,10 +765,7 @@ declare namespace Taro { $preload(key: string, value: any): void $preload(key: object): void - setState( - state: ((prevState: Readonly, props: P) => Pick | S) | (Pick | S), - callback?: () => any - ): void + setState(state: ((prevState: Readonly, props: P) => Pick | S) | (Pick | S), callback?: () => any): void forceUpdate(callBack?: () => any): void @@ -892,7 +895,7 @@ declare namespace Taro { */ namespace request { - type Promised = { + type Promised < T extends any | string | ArrayBuffer = any > = { /** * 开发者服务器返回的数据 * @@ -927,7 +930,7 @@ declare namespace Taro { */ abort(): void } - type Param

= { + type Param < P extends any | string | ArrayBuffer = any > = { /** * 开发者服务器接口地址 */ @@ -1118,18 +1121,7 @@ declare namespace Taro { */ function request(OBJECT: request.Param): request.requestTask - type arrayBuffer = - | Uint8Array - | Int8Array - | Uint8Array - | Uint8ClampedArray - | Int16Array - | Uint16Array - | Int32Array - | Uint32Array - | Float32Array - | Float64Array - | ArrayBuffer + type arrayBuffer = Uint8Array | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | ArrayBuffer /** * 将 ArrayBuffer 数据转成 Base64 字符串 @@ -1547,8 +1539,8 @@ declare namespace Taro { function sendSocketMessage(OBJECT: sendSocketMessage.Param): Promise namespace onSocketMessage { - type Param = (res: ParamParam) => any - type ParamParam = { + type Param < T = any > = (res: ParamParam) => any + type ParamParam < T extends any | string | ArrayBuffer = any > = { /** * 服务器返回的消息 */ @@ -1706,8 +1698,8 @@ declare namespace Taro { } } namespace onMessage { - type Param = (res: ParamParam) => any - type ParamParam = { + type Param < T = any > = (res: ParamParam) => any + type ParamParam < T extends any | string | ArrayBuffer = any > = { /** * 服务器返回的消息 */ @@ -1721,6 +1713,7 @@ declare namespace Taro { * WebSocket 任务,可通过 [Taro.connectSocket()](https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.html) 接口创建返回。 */ class SocketTask { + /** * websocket 当前的连接 ID。 */ @@ -1939,15 +1932,7 @@ declare namespace Taro { * * @since 1.9.90 */ - orientation: - | 'up' - | 'down' - | 'left' - | 'right' - | 'up-mirrored' - | 'down-mirrored ' - | 'left-mirrored' - | 'right-mirrored' + orientation: 'up' | 'down' | 'left' | 'right' | 'up-mirrored' | 'down-mirrored ' | 'left-mirrored' | 'right-mirrored' /** * 返回图片的格式 * @@ -2483,9 +2468,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.getBackgroundAudioPlayerState.html */ - function getBackgroundAudioPlayerState( - OBJECT?: getBackgroundAudioPlayerState.Param - ): Promise + function getBackgroundAudioPlayerState(OBJECT?: getBackgroundAudioPlayerState.Param): Promise namespace playBackgroundAudio { type Param = { @@ -5473,9 +5456,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.startBluetoothDevicesDiscovery.html */ - function startBluetoothDevicesDiscovery( - OBJECT?: startBluetoothDevicesDiscovery.Param - ): Promise + function startBluetoothDevicesDiscovery(OBJECT?: startBluetoothDevicesDiscovery.Param): Promise namespace stopBluetoothDevicesDiscovery { type Promised = { @@ -5502,9 +5483,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.stopBluetoothDevicesDiscovery.html */ - function stopBluetoothDevicesDiscovery( - OBJECT?: stopBluetoothDevicesDiscovery.Param - ): Promise + function stopBluetoothDevicesDiscovery(OBJECT?: stopBluetoothDevicesDiscovery.Param): Promise namespace getBluetoothDevices { type Promised = { @@ -5720,9 +5699,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.getConnectedBluetoothDevices.html */ - function getConnectedBluetoothDevices( - OBJECT: getConnectedBluetoothDevices.Param - ): Promise + function getConnectedBluetoothDevices(OBJECT: getConnectedBluetoothDevices.Param): Promise namespace createBLEConnection { type Promised = { @@ -5967,9 +5944,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceCharacteristics.html */ - function getBLEDeviceCharacteristics( - OBJECT: getBLEDeviceCharacteristics.Param - ): Promise + function getBLEDeviceCharacteristics(OBJECT: getBLEDeviceCharacteristics.Param): Promise namespace readBLECharacteristicValue { type Promised = { @@ -6028,9 +6003,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.readBLECharacteristicValue.html */ - function readBLECharacteristicValue( - OBJECT: readBLECharacteristicValue.Param - ): Promise + function readBLECharacteristicValue(OBJECT: readBLECharacteristicValue.Param): Promise namespace writeBLECharacteristicValue { type Promised = { @@ -6095,9 +6068,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.writeBLECharacteristicValue.html */ - function writeBLECharacteristicValue( - OBJECT: writeBLECharacteristicValue.Param - ): Promise + function writeBLECharacteristicValue(OBJECT: writeBLECharacteristicValue.Param): Promise namespace notifyBLECharacteristicValueChange { type Promised = { @@ -6155,9 +6126,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.notifyBLECharacteristicValueChange.html */ - function notifyBLECharacteristicValueChange( - OBJECT: notifyBLECharacteristicValueChange.Param - ): Promise + function notifyBLECharacteristicValueChange(OBJECT: notifyBLECharacteristicValueChange.Param): Promise namespace onBLECharacteristicValueChange { type Param = (res: ParamParam) => any @@ -9116,9 +9085,7 @@ declare namespace Taro { checkAliveType?: number } } - function checkIsSupportFacialRecognition( - OBJECT?: checkIsSupportFacialRecognition.Param - ): Promise + function checkIsSupportFacialRecognition(OBJECT?: checkIsSupportFacialRecognition.Param): Promise namespace startFacialRecognitionVerify { type Promised = { @@ -9132,9 +9099,7 @@ declare namespace Taro { checkAliveType?: number } } - function startFacialRecognitionVerify( - OBJECT?: startFacialRecognitionVerify.Param - ): Promise + function startFacialRecognitionVerify(OBJECT?: startFacialRecognitionVerify.Param): Promise namespace startFacialRecognitionVerifyAndUploadVideo { type Promised = { @@ -9148,9 +9113,7 @@ declare namespace Taro { checkAliveType?: number } } - function startFacialRecognitionVerifyAndUploadVideo( - OBJECT?: startFacialRecognitionVerifyAndUploadVideo.Param - ): Promise + function startFacialRecognitionVerifyAndUploadVideo(OBJECT?: startFacialRecognitionVerifyAndUploadVideo.Param): Promise namespace requestPayment { type Param = { @@ -9917,9 +9880,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/soter/wx.checkIsSupportSoterAuthentication.html */ - function checkIsSupportSoterAuthentication( - OBJECT?: checkIsSupportSoterAuthentication.Param - ): Promise + function checkIsSupportSoterAuthentication(OBJECT?: checkIsSupportSoterAuthentication.Param): Promise namespace startSoterAuthentication { type Promised = { @@ -10062,9 +10023,7 @@ declare namespace Taro { ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/soter/wx.checkIsSoterEnrolledInDevice.html */ - function checkIsSoterEnrolledInDevice( - OBJECT: checkIsSoterEnrolledInDevice.Param - ): Promise + function checkIsSoterEnrolledInDevice(OBJECT: checkIsSoterEnrolledInDevice.Param): Promise /** * @since 2.0.1 @@ -10320,9 +10279,7 @@ declare namespace Taro { getContext(contextType: string): any } namespace CanvasContext { - namespace draw { - type Param1 = () => any - } + namespace draw { type Param1 = () => any } } interface Color {} @@ -11654,7 +11611,7 @@ declare namespace Taro { /** * 来源信息。从另一个小程序、公众号或 App 进入小程序时返回。否则返回 {}。 */ - referrerInfo: { appId: string; extraData: { [k: string]: any } } + referrerInfo: { appId: string, extraData: { [k: string]: any} } } } @@ -11679,11 +11636,11 @@ declare namespace Taro { /** * 不存在页面的路径 */ - path: string + path: string, /** * 打开不存在页面的 query 参数 */ - query: Object + query: Object, /** * 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */