How to avoid "no-promise-executor-return" in this situation?

Advertisements code: export function sleep(ms: number): Promise<void> { return new Promise<void>((resolve) => setTimeout(resolve, ms)); } Docs link: no-promise-executor-return I have tried in many ways to avoid this error. Unfortunately, to no avail. >Solution : This is an arrow function thing. () => 0 is the same as function() { return 0 }. So your promise… Read More How to avoid "no-promise-executor-return" in this situation?

X is declared but its value is never read. Though I have used the variable

Advertisements I’m using some properties in my Angular component, but I’m getting the following warnings in VSCode: ‘_id’ is declared but its value is never read.ts(6133) (property) ItemEditComponent._id: number | undefined ‘_isModeEdit’ is declared but its value is never read.ts(6133) (property) ItemEditComponent._isModeEdit: boolean This is also my component: import { Component, OnDestroy, OnInit, inject }… Read More X is declared but its value is never read. Though I have used the variable

Must use destructuring theme assignment react/destructuring-assignment

Advertisements I am trying to start a typescript project but i’m getting a bunch of errors relating to "Line 92:27: Must use destructuring theme assignment react/destructuring-assignment". I have about 10 of these errors. The error specifically for above is relating to the code for line 92 is: <StyledClose color={theme.colors.textSubtle} onClick={removeThisPopup} /> This is apart of… Read More Must use destructuring theme assignment react/destructuring-assignment

@typescript-eslint/no-floating-promises with const function declaration

Advertisements I’m having trouble understanding why the @typescript-eslint/no-floating-promises works with some, but not all my async functions. In my understanding, the following 2 functions are equivalent const getUser = async (userId: string): Promise<User> => { const userRef = await getUsersCollection().doc(userId).get() return userRef.data() } async function getUser2(userId: string) { const userRef = await getUsersCollection().doc(userId).get() return userRef.data()… Read More @typescript-eslint/no-floating-promises with const function declaration

Property 'innerText' does not exist on type 'EventTarget' –TypeScript

Advertisements i have a two column mega menu and i want when user hover a category, that category items to be displayed dynamic on second column . i’m using typescript, the problem is when i wanna update the megaMenu state i get a red underline saying Property ‘innerText’ does not exist on type ‘EventTarget’. why… Read More Property 'innerText' does not exist on type 'EventTarget' –TypeScript

Accidentally running TypeScript code directly with `node` without `ts-node`, why does it work?

Advertisements I have set up a very simple node.js project with TypeScript. My package.json, from which you can see what packages I have installed (there is no ts-node), looks like this: { "name": "mydemo", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "lint": "eslint . –fix", "test": "echo \"Error: no test specified\" && exit 1",… Read More Accidentally running TypeScript code directly with `node` without `ts-node`, why does it work?

Eslint combining naming conventions

Advertisements I want to combine snake_case and PascalCase naming conventions. So, declaring a class its name must match the following format strictly: Pascal_Snake, Pascal_Snake_Pascal_Etc, OnlyPascal, Pascal. That’s what I’m trying to do in my esling.config: ‘@typescript-eslint/naming-convention’: [ { selector: ‘class’, format: null, custom: { "regex": "([A-Z]\\w*_?[A-Z]\\w+)|([A-Z]\\w*[A-Z]?\\w+)", "match": true, }, }, ] Unfortunately, this regex is… Read More Eslint combining naming conventions

ESLint rule for arrow function requiring return type

Advertisements I’m having below arrow function in my angular project: this.httpClient.get(‘url’).subscribe((response)=>{ }); In the above code ESLint should throw an error for not specifying return type. >Solution : Check the rule @typescript-eslint/explicit-function-return-type. You need to set the option allowTypedFunctionExpressions to false. If you are using .eslintrc: "@typescript-eslint/explicit-function-return-type": [ "error", { "allowTypedFunctionExpressions": false } ]