简体   繁体   English

ESLint:“any”的不安全分配和“any”类型值的不安全调用

[英]ESLint: Unsafe assignment of an `any` and Unsafe call of an `any` typed value

Consider the following test code:考虑以下测试代码:

import { isHtmlLinkDescriptor } from '@remix-run/react/links'
import invariant from 'tiny-invariant'
import { links } from '~/root'

it('should return a rel=stylesheet', () => {
  const response = links()

  invariant(isHtmlLinkDescriptor(response[0]))

  expect(response[0].rel).toBe('stylesheet')
})

and the implementation:和实施:

import { LinksFunction } from 'remix'
import tailwindProdUrl from '~/styles/tailwind.css'

export const links: LinksFunction = () => {
  const href =
    process.env.NODE_ENV !== 'production' ? './tailwind.css' : tailwindProdUrl

  return [{ rel: 'stylesheet', href }]
}

Where LinksFunction is defined here and here . LinksFunction 在此处此处定义的位置。

Why is ESLint complaining about "Unsafe assignment of an any value."为什么 ESLint 抱怨“ any值的不安全分配”。 and "Unsafe call of an any typed value."和“ any类型值的不安全调用”。 in the line below?在下面的行中?

const response = links()

You have a wrong import in the second snippet.您在第二个片段中有错误的导入。 It should be:它应该是:

import { LinksFunction } from '@remix-run/server-runtime';

or also, if you are working with TypeScript 3.8 or later:或者,如果您使用的是 TypeScript 3.8 或更高版本:

import type { LinksFunction } from '@remix-run/server-runtime';

The fact that LinksFunction is being only used as a type in the code you are showing means that the TypeScript compiler could still succeed in compiling your modules under certain circumstances, despite the missing type definitions. LinksFunction仅用作您显示的代码中的类型这一事实意味着 TypeScript 编译器在某些情况下仍然可以成功编译您的模块,尽管缺少类型定义。

暂无
暂无

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

相关问题 @typescript-eslint/no-unsafe-assignment:任何值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value Typescript:ESLint:任何类型值的不安全返回 @typescript-eslint/no-unsafe-return - Typescript : ESLint : Unsafe return of an any typed value @typescript-eslint/no-unsafe-return 元素引用<any> .nativeElement:任何抛出“任何类型值的不安全调用”错误</any> - ElementRef<any>.nativeElement: any throwing "Unsafe call of an any typed value" error 任何值上的 eslint 错误不安全成员访问 ['content-type'] - eslint error Unsafe member access ['content-type'] on an any value UIComponent.getRouterFor 显示 TypeScript 错误:“任何”类型值的不安全返回 - UIComponent.getRouterFor shows TypeScript error: Unsafe return of an 'any' typed value 收到此打字稿错误:对任何值不安全的成员访问 [key] - Getting this typescript error: Unsafe member access [key] on an any value 对 Typescript function 中的 return 语句不安全地使用“any”类型的表达式 - Unsafe use of expression of type 'any' for return statements in Typescript function React JS - ESLint - 使用 UNSAFE_componentWillMount、UNSAFE_componentWillUpdate 和 UNSAFE_componentWillReceiveProps 忽略组件的规则 - React JS - ESLint - Rules for ignoring components with UNSAFE_componentWillMount, UNSAFE_componentWillUpdate, and UNSAFE_componentWillReceiveProps @typescript-eslint/no-unsafe-* 规则的新 eslint 错误 - New eslint errors with the @typescript-eslint/no-unsafe-* rules 为什么ESLint插件不标记不安全的方法 - Why Isn't ESLint plugin flagging unsafe methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM