简体   繁体   English

Typescript - eslint 错误分配给类型的“任何”类型的不安全参数

[英]Typescript - eslint error Unsafe argument of type 'any' assigned to a type

I have the following code:我有以下代码:

import * as messagesData from '../../data/messages.json';
await test.step(
        'Add second product to the cart product listing page',
        async () => {
          await categoryPage.clickAddToCartBtn(1);
          const successMessage = categoryPage.getSuccessMessage();
          await expect(successMessage).toBeVisible();
          await expect(successMessage).toHaveText(
            messagesData.successAddToCartMessage
          );
        }
      );

I use Playwright and Typescript.我使用 Playwright 和 Typescript。 messagesData.successAddToCartMessage is string entry from a JSON file. messagesData.successAddToCartMessage是 JSON 文件中的字符串条目。 So why does it complain that this is of type any?那么为什么它抱怨这是任何类型的呢?
I am not sure why I get this eslint error in the last line:我不知道为什么我在最后一行得到这个 eslint 错误:

Unsafe argument of type `any` assigned to a parameter of type `string | RegExp | (string | RegExp)[]` 

I have similar code a few lines below where it doesn't complain.我在下面几行没有抱怨的地方有类似的代码。
I am super confused.我超级困惑。 Please help!请帮忙!

I don't know why this glitch happened, but I needed to restart VS Code and then the error was gone:/ Very annoying, I must say.我不知道为什么会发生这个故障,但我需要重新启动 VS Code,然后错误就消失了:/ 非常烦人,我必须说。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeScript 不安全地使用“任何”类型的表达式错误 - TypeScript Unsafe use of expression of type 'any' ERROR 任何值上的 eslint 错误不安全成员访问 ['content-type'] - eslint error Unsafe member access ['content-type'] on an any value 任何值 ESLint 错误的 Typescript 不安全分配 - Typescript Unsafe Assignment of An Any Value ESLint Error Typescript:function,枚举类型的参数分配给回调,参数类型为字符串 - Typescript: function with argument of enum type assigned to callback with argument type of string 为什么任何可以分配给 TypeScript 中的每种类型 - Why can any be assigned to every type in TypeScript Protracto-TypeScript错误:参数类型boolean未分配给参数类型boolean - Protracto-TypeScript Error: Argument type boolean not assigned to parameter type boolean @typescript-eslint/no-unsafe-assignment: `any` 值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment:任何值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value 对 Typescript function 中的 return 语句不安全地使用“any”类型的表达式 - Unsafe use of expression of type 'any' for return statements in Typescript function Typescript:ESLint:任何类型值的不安全返回 @typescript-eslint/no-unsafe-return - Typescript : ESLint : Unsafe return of an any typed value @typescript-eslint/no-unsafe-return
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM