我有一个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一起使用,需要获得参数?
相关:如何使用文件通过JSDoc函数返回的功能和静止悬而未决的问题#1286“ 支持咖喱功能 ”
—
BERGI