English 中文(简体)
ESLint + TypeScript Esklint; 如何使函数返回承诺
原标题:ESLint + TypeScript ESlint; How to make a function returning a promise
I have ESLint + TypeScript ESlint which no rules in them changed in the project. In that project is a function, where I want to return a promise which is axios.get call, but I am unable to get it to pass linting rules. When I do: import { ResponseType } from axios const getPosts = async (): Promise => { return axios.get("https://jsonplaceholder.typicode.com/posts") } I get: Returning an awaited promise is required in this context. eslint(@typescript-eslint/return-await) So, I added await: import { ResponseType } from axios const getPosts = async (): Promise => { return await axios.get("https://jsonplaceholder.typicode.com/posts") } But this lead to another error: Redundant use of await on a return value. eslint(no-return-await) I also tried to get rid of async, but that lead to: Functions that return promises must be async. eslint(@typescript-eslint/promise-function-async) I doubt that default ESLint conflicts with TypeScript ESlint and assume, that there is some other solution to rewrite the function, so that it passes for both. What would be some other option to rewrite that function? Here documentation for both: https://eslint.org/docs/latest/rules/no-return-await https://typescript-eslint.io/rules/return-await
问题回答
General principle: If some JS eslint rule conflicts with TS rule, disable JS rule In many cases TS rule may conflict with JS rule with same name In your case, your rule conflicts with opposite rule which should have been disabled Find out why it gets enabled, or just disable is and forget




相关问题
store data in memory with nestjs

I am trying to persist some data in my nestjs server so I can then use that data in my client app through http requests. I have created a products.service.ts file with the function getAllData() that ...

React Hook Form Error on custom Input component

I am having a problem when I use react hook form + zod in my application, in short the inputs never change value and I get the following error in the console: Warning: Function components cannot be ...

Updatable promises using proxy in JavaScript

EDIT: I ve updated this question, and the old question is moved here. A POC can be found on this jsfiddle or the snippet below GOAL: The goal here is to make or rather simulate a promise that can be ...

热门标签