From 98d141171fc2ba2f46a034fcf5e12b22a14da778 Mon Sep 17 00:00:00 2001 From: jedmao Date: Tue, 3 Sep 2019 15:45:27 -0500 Subject: [PATCH] fix TSDoc comments --- src/applyMiddleware.ts | 7 +++++-- src/compose.ts | 2 +- src/createStore.ts | 28 ++++++++++++++-------------- src/types/middleware.ts | 2 +- src/utils/isPlainObject.ts | 6 +++--- src/utils/warning.ts | 5 ++--- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/applyMiddleware.ts b/src/applyMiddleware.ts index 7bddf3fc05..f735843252 100644 --- a/src/applyMiddleware.ts +++ b/src/applyMiddleware.ts @@ -17,8 +17,11 @@ import { Reducer } from './types/reducers' * Note that each middleware will be given the `dispatch` and `getState` functions * as named arguments. * - * @param {...Function} middlewares The middleware chain to be applied. - * @returns {Function} A store enhancer applying the middleware. + * @param middlewares The middleware chain to be applied. + * @returns A store enhancer applying the middleware. + * + * @template Ext Dispatch signature added by a middleware. + * @template S The type of the state supported by a middleware. */ export default function applyMiddleware(): StoreEnhancer export default function applyMiddleware( diff --git a/src/compose.ts b/src/compose.ts index 2ed13051a2..fcbfd70d7b 100644 --- a/src/compose.ts +++ b/src/compose.ts @@ -9,7 +9,7 @@ type Func3 = (a1: T1, a2: T2, a3: T3, ...args: any[]) => R * resulting composite function. * * @param funcs The functions to compose. - * @returns R function obtained by composing the argument functions from right + * @returns A function obtained by composing the argument functions from right * to left. For example, `compose(f, g, h)` is identical to doing * `(...args) => f(g(h(...args)))`. */ diff --git a/src/createStore.ts b/src/createStore.ts index 0a0d35b835..a75fc2a304 100644 --- a/src/createStore.ts +++ b/src/createStore.ts @@ -21,21 +21,21 @@ import isPlainObject from './utils/isPlainObject' * parts of the state tree respond to actions, you may combine several reducers * into a single reducer function by using `combineReducers`. * - * @param {Function} reducer A function that returns the next state tree, given + * @param reducer A function that returns the next state tree, given * the current state tree and the action to handle. * - * @param {any} [preloadedState] The initial state. You may optionally specify it + * @param preloadedState The initial state. You may optionally specify it * to hydrate the state from the server in universal apps, or to restore a * previously serialized user session. * If you use `combineReducers` to produce the root reducer function, this must be * an object with the same shape as `combineReducers` keys. * - * @param {Function} [enhancer] The store enhancer. You may optionally specify it + * @param enhancer The store enhancer. You may optionally specify it * to enhance the store with third-party capabilities such as middleware, * time travel, persistence, etc. The only store enhancer that ships with Redux * is `applyMiddleware()`. * - * @returns {Store} A Redux store that lets you read the state, dispatch actions + * @returns A Redux store that lets you read the state, dispatch actions * and subscribe to changes. */ export default function createStore< @@ -119,7 +119,7 @@ export default function createStore< /** * Reads the state tree managed by the store. * - * @returns {any} The current state tree of your application. + * @returns The current state tree of your application. */ function getState(): S { if (isDispatching) { @@ -153,8 +153,8 @@ export default function createStore< * registered before the `dispatch()` started will be called with the latest * state by the time it exits. * - * @param {Function} listener A callback to be invoked on every dispatch. - * @returns {Function} A function to remove this change listener. + * @param listener A callback to be invoked on every dispatch. + * @returns A function to remove this change listener. */ function subscribe(listener: () => void) { if (typeof listener !== 'function') { @@ -210,13 +210,13 @@ export default function createStore< * example, see the documentation for the `redux-thunk` package. Even the * middleware will eventually dispatch plain object actions using this method. * - * @param {Object} action A plain object representing “what changed”. It is + * @param action A plain object representing “what changed”. It is * a good idea to keep actions serializable so you can record and replay user * sessions, or use the time travelling `redux-devtools`. An action must have * a `type` property which may not be `undefined`. It is a good idea to use * string constants for action types. * - * @returns {Object} For convenience, the same action object you dispatched. + * @returns For convenience, the same action object you dispatched. * * Note that, if you use a custom middleware, it may wrap `dispatch()` to * return something else (for example, a Promise you can await). @@ -263,8 +263,8 @@ export default function createStore< * load some of the reducers dynamically. You might also need this if you * implement a hot reloading mechanism for Redux. * - * @param {Function} nextReducer The reducer for the store to use instead. - * @returns {Store} The same store instance with a new reducer in place. + * @param nextReducer The reducer for the store to use instead. + * @returns The same store instance with a new reducer in place. */ function replaceReducer( nextReducer: Reducer @@ -296,7 +296,7 @@ export default function createStore< /** * Interoperability point for observable/reactive libraries. - * @returns {observable} A minimal observable of state changes. + * @returns A minimal observable of state changes. * For more information, see the observable proposal: * https://github.com/tc39/proposal-observable */ @@ -305,9 +305,9 @@ export default function createStore< return { /** * The minimal observable subscription method. - * @param {Object} observer Any object that can be used as an observer. + * @param observer Any object that can be used as an observer. * The observer object should have a `next` method. - * @returns {subscription} An object with an `unsubscribe` method that can + * @returns An object with an `unsubscribe` method that can * be used to unsubscribe the observable from the store, and prevent further * emission of values from the observable. */ diff --git a/src/types/middleware.ts b/src/types/middleware.ts index 3aad7cac0a..d631d988da 100644 --- a/src/types/middleware.ts +++ b/src/types/middleware.ts @@ -21,7 +21,7 @@ export interface MiddlewareAPI { * installed. */ export interface Middleware< - _DispatchExt = {}, // TODO: remove unused component + _DispatchExt = {}, // TODO: remove unused component (breaking change) S = any, D extends Dispatch = Dispatch > { diff --git a/src/utils/isPlainObject.ts b/src/utils/isPlainObject.ts index 4281d65d24..9d1956328a 100644 --- a/src/utils/isPlainObject.ts +++ b/src/utils/isPlainObject.ts @@ -1,8 +1,8 @@ /** - * @param {any} obj The object to inspect. - * @returns {boolean} True if the argument appears to be a plain object. + * @param obj The object to inspect. + * @returns True if the argument appears to be a plain object. */ -export default function isPlainObject(obj: unknown) { +export default function isPlainObject(obj: any): boolean { if (typeof obj !== 'object' || obj === null) return false let proto = obj diff --git a/src/utils/warning.ts b/src/utils/warning.ts index e0ea312f5d..cefc5d1da6 100644 --- a/src/utils/warning.ts +++ b/src/utils/warning.ts @@ -1,10 +1,9 @@ /** * Prints a warning in the console if it exists. * - * @param {String} message The warning message. - * @returns {void} + * @param message The warning message. */ -export default function warning(message: string) { +export default function warning(message: string): void { /* eslint-disable no-console */ if (typeof console !== 'undefined' && typeof console.error === 'function') { console.error(message)