首页 > 解决方案 > tslint:dsiable 不起作用。可能的原因是什么?

问题描述

尽管已经设置,但tslint:disable我收到了 tslint 警告。

我得到的具体警告是:

[ts] Argument of type 'string' is not assignable to parameter of type 'RequestInit | undefined'.
(parameter) options: string

[ts] Parameter 'response' implicitly has an 'any' type.
(parameter) response: Response

这是我的代码。

/* tslint:disable */

// imports 
export async function fetchUrl(url: string, options: string) {
  return fetch(url, options)
    .then(async (response) => response.json())
    .then((data: any) => data.data);
}

// other code

/* tslint:enable */

为什么即使我禁用了 tslint 也会收到这些警告?

如何摆脱此文件的错误消息?

标签: typescript

解决方案


这些错误来自 TypeScript 编译器本身,如[ts]错误中所示。

以下将消除错误,但您需要检查使用该功能的任何内容是否正确。即具有有效options参数。

export async function fetchUrl(url: string, options: RequestInit) {
  return fetch(url, options)
    .then(async (response: Response) => response.json())
    .then((data: any) => data.data);
}

推荐阅读