我具有以下工厂功能:
/**
* Create a CRUD interface
* @param {string} collectionName Name of the table/collection on the API side
* @return {Object}
*/
export default function createCrudInterface(collectionName) {
return {
/**
* Create a new item
* @param {Object} data JSON request data
* @param {import('./api-call').ApiOptions} [apiOptions] API call options
* @return {Promise}
*/
create(data, apiOptions) {
return apiCall('POST', `/${collectionName}`, null, data, apiOptions);
},
/**
* Gets one or more items
* @param {(string|number)} [id] ID of item
* @param {Object} [queryParams] Query parameters
* @param {import('./api-call').ApiOptions} [apiOptions] API call options
* @return {Promise}
*/
get(id, queryParams, apiOptions) {
return apiCall(
'GET',
`/${collectionName}` + (id && `/${id}`),
queryParams,
null,
apiOptions
);
},
/**
* Update an item
* @param {(string|number)} id ID of item
* @param {Object} data JSON request data
* @param {import('./api-call').ApiOptions} [apiOptions] API call options
* @return {Promise}
*/
update(id, data, apiOptions) {
return apiCall('PUT', `/${collectionName}/${id}`, null, data, apiOptions);
},
/**
* Delete one or more items
* @param {(string|number|string[]|number[])} idOrIds ID of item
* @param {import('./api-call').ApiOptions} [apiOptions] API call options
*/
delete(idOrIds, apiOptions) {
const batch = Array.isArray(idOrIds);
return apiCall(
'DELETE',
`/${collectionName}` + (batch ? '' : `/${idOrIds}`),
null,
batch ? { ids: idOrIds } : null,
apiOptions
);
},
};
}
此似乎就像它可以工作,但不起作用:
const blah = createCrudInterface('blah');
当我输入blah.create(
时,VS Code IntelliSense不知道建议什么。它不是在拉我定义的方法JSDoc。
执行此操作的正确方法是什么?