typescript-eslint

Is there a typescript-eslint rule that alerts you when you use a method as a boolean?

前提是你 提交于 2021-02-11 16:30:48
问题 In Javascript, I sometimes accidentally write: if (obj.method) { // <-- bad ... } instead of if (obj.method()) { // <-- good ... } Given that typescript-eslint is typeaware, is there a rule that detects this usage? I would say that 99/100 times, I am not trying to use the method as a boolean. 回答1: If you turn on typescript's strictNullChecks compiler option (or the catch-all strict compiler option), TS will do this specific check for you automatically! Example: https://www.typescriptlang.org

Is there a typescript-eslint rule that alerts you when you use a method as a boolean?

南笙酒味 提交于 2021-02-11 16:27:49
问题 In Javascript, I sometimes accidentally write: if (obj.method) { // <-- bad ... } instead of if (obj.method()) { // <-- good ... } Given that typescript-eslint is typeaware, is there a rule that detects this usage? I would say that 99/100 times, I am not trying to use the method as a boolean. 回答1: If you turn on typescript's strictNullChecks compiler option (or the catch-all strict compiler option), TS will do this specific check for you automatically! Example: https://www.typescriptlang.org

ESLint error when trying to lint Angular templates

杀马特。学长 韩版系。学妹 提交于 2021-02-10 15:58:08
问题 I have an Angular 10 app set up with eslint and prettier, which worked fine so far for linting Typescript files. I'm now trying to lint my component template files as well following this doc. But when I run it with eslint . --ext .js,.ts,.component.html --fix I keep getting Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript

ESLint error when trying to lint Angular templates

被刻印的时光 ゝ 提交于 2021-02-10 15:56:59
问题 I have an Angular 10 app set up with eslint and prettier, which worked fine so far for linting Typescript files. I'm now trying to lint my component template files as well following this doc. But when I run it with eslint . --ext .js,.ts,.component.html --fix I keep getting Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript

How to use ESLint TypeScript Airbnb configuration?

谁都会走 提交于 2020-12-15 06:50:56
问题 I try to install and use ESLint Airbnb configuration for TypeScript for several days and I cannot make it work. Can somebody give installation and configuration steps of a working configuration, please? Below is one of my attempts to lint this code base using Airbnb convention. Airbnb configuration doesn't support Typescript ESLint 3.0 yet, so I will install TypeScript ESLint 2.34. Typescript ESLint 2.34 doesn't support ESLint 7 yet, so I will install ESLint 6.x. Typescript ESLint 2.34 doesn

“parserOptions.project” has been set for @typescript-eslint/parser

半城伤御伤魂 提交于 2020-11-24 16:32:07
问题 I created a new React Native project with --template typescript I deleted the template directory which came as part of the boilerplate. I then proceeded to add ESLint: module.exports = { parser: "@typescript-eslint/parser", plugins: ["@typescript-eslint"], extends: ["airbnb-typescript-prettier"] }; However, when I open babel.config.js , I get this error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: /Users/Dan

Typescript: Why doesn't visual studio code report the same errors that the command line tsc does?

扶醉桌前 提交于 2020-03-25 13:48:34
问题 If I intentionally make a typo in my code I will get an error. Here is the correct code: declare const State: TwineState; If I delete the last character and then type tsc on the command line, it gives me this error: tsc/prod.spec.ts:7:22 - error TS2304: Cannot find name 'TwineStat'. 7 declare const State: TwineStat; But Visual Studio Code doesn't seem to realize there's any error. How I get my editor to show me the same errors that the tsc command recognizes? I'm pretty new to all these

Typescript: Why doesn't visual studio code report the same errors that the command line tsc does?

淺唱寂寞╮ 提交于 2020-03-25 13:48:09
问题 If I intentionally make a typo in my code I will get an error. Here is the correct code: declare const State: TwineState; If I delete the last character and then type tsc on the command line, it gives me this error: tsc/prod.spec.ts:7:22 - error TS2304: Cannot find name 'TwineStat'. 7 declare const State: TwineStat; But Visual Studio Code doesn't seem to realize there's any error. How I get my editor to show me the same errors that the tsc command recognizes? I'm pretty new to all these