【发布时间】:2021-05-18 11:50:36
【问题描述】:
我有以下代码,TypeScript 对此很满意。它正确地将RequestInit 视为fetch 请求的选项。我还启用了启用 no-undefined-types 的 ESLint JSDoc 插件。当我针对此代码运行 ESLint 时,我收到以下错误 The type 'RequestInit' is undefined。
有没有办法可以公开 TypeScript 的内置类型定义以使 JSDoc 了解它们?我为 TypeScript 配置了 JSDoc 插件。 settings.jsdoc.mode = "typescript"
// @ts-check
/** @type {RequestInit} */
const FETCH_OPTIONS = {
cache: 'no-cache',
credentials: 'include',
method: 'GET',
mode: 'cors'
};
fetch('/api/getsomething/3', FETCH_OPTIONS)
.then(nextFn)
.catch(errorFn)
【问题讨论】:
-
您是否尝试过对
@types/react的显式类型引用,如下所述:typescriptlang.org/docs/handbook/… -
@DustInCompetent 我尝试使用
/// <reference lib="dom" />,因为这是RequestInit所在的位置,而JSDoc 仍然不知道这些类型。
标签: typescript jsdoc