我有一个 ES6 风格的函数,它使用带有asyncPipe.
import { getItemAsync } from 'expo-secure-store';
const asyncPipe = (...fns) => x => fns.reduce(async (y, f) => f(await y), x);
const getToken = () => getItemAsync('token');
const liftedGetToken = async ({ ...rest }) => ({
token: await getToken(),
...rest,
});
const liftedFetch = ({ body, route, token, method = 'GET' } = {}) =>
fetch(route, {
...(body && { body: JSON.stringify(body) }),
headers: {
'Content-Type': 'application/json',
...(token && { Authorization: `Bearer ${token}` }),
},
method,
});
const json = res => res.json();
/**
* @method
* @param {Object} fetchSettings the settings for the fetch request
* @param {Object} fetchSettings.body the body of the request
* @param {string} fetchSettings.route the URL of the request
* @param {string} fetchSettings.method the method of the request
* @param {string} fetchSettings.token should only be used for testing and unauthenticated requests
*/
const request = asyncPipe(liftedGetToken, liftedFetch, json);
如您所见,我尝试向其添加 JSDoc 描述。但是当我在我的编辑器 VSCode 的任何地方使用它时,不会建议它的参数。你如何用 JSDoc 声明这些类型的函数?以及如何获取此函数的参数以与 Intellisense 一起使用?
LEATH
弑天下
相关分类