Questions tagged [tslint]

tslint is a static analysis linter for TypeScript.

tslint is a linter for the language, similar to jslint.

Use this tag on questions about:

  • installation
  • command-line options
  • default/built-in rules
  • rule flags
  • Custom formatters
  • creation of custom rules

Github home of tslint
NPM home of tslint

1054 questions
1265
votes
6 answers

In TypeScript, what is the ! (exclamation mark / bang) operator when dereferencing a member?

When looking at the source code for a tslint rule, I came across the following statement: if (node.parent!.kind === ts.SyntaxKind.ObjectLiteralExpression) { return; } Notice the ! operator after node.parent. Interesting! I first tried compiling…
Mike Chamberlain
  • 39,692
  • 27
  • 110
  • 158
512
votes
11 answers

How to use `@ts-ignore` for a block?

The // @ts-ignore comment enables the TypeScript compiler to ignore the line below it. How can one ignore a whole block of code with TypeScript?
lovelikelando
  • 7,593
  • 6
  • 32
  • 50
319
votes
10 answers

Subscribe is deprecated: Use an observer instead of an error callback

When I run the linter it says: subscribe is deprecated: Use an observer instead of an error callback Code from this angular app: this.userService.updateUser(data).pipe( tap(() => {bla bla bla}) ).subscribe( …
ismaestro
  • 7,561
  • 8
  • 37
  • 50
289
votes
6 answers

tslint / codelyzer / ng lint error: "for (... in ...) statements must be filtered with an if statement"

Lint error message: src/app/detail/edit/edit.component.ts[111, 5]: for (... in ...) statements must be filtered with an if statement Code snippet (It is a working code. It is also available at angular.io form validation section): for (const…
Jek
  • 5,546
  • 9
  • 37
  • 67
272
votes
10 answers

TSLint extension throwing errors in my Angular application running in Visual Studio Code

I recently started seeing, what seems like, TSLint errors. They look like this: Not using the local TSLint version found for '/Users/myname/myproject/client/src/app/likes/likee/likee.component.ts'. To enable code execution from the current…
chuckd
  • 13,460
  • 29
  • 152
  • 331
167
votes
10 answers

How to ignore a particular directory or file for tslint?

The IDE being used is WebStorm 11.0.3, the tslint is configured and works, but, it hangs because it tries to parse large *.d.ts library files. Is there a way to ignore a particular file or directory?
user3330840
  • 6,143
  • 7
  • 26
  • 39
149
votes
12 answers

tslint how to disable error "someVariable is declared but its value is never read"

I'm using tslint, and got the error. 'myVariable' is declared but its value is never read. I went to the website that documents the rules https://palantir.github.io/tslint/rules/ and searched for the string is declared but its value is never read…
PatS
  • 8,833
  • 12
  • 57
  • 100
142
votes
12 answers

tslint says calls to console.log are not allowed - How do I allow this?

I just started using create-react-app with typescript create-react-app my-app --scripts-version=react-scripts-ts and the default tslint.json configuration does not allow console.log(). How can I (for now) enable console.log? The docs for this are…
PatS
  • 8,833
  • 12
  • 57
  • 100
119
votes
8 answers

location.reload(true) is deprecated

I know that it is not ideal to reload an Angular Single Page Application. However there is a place that I need to reload the full application. TSLint says that reload is deprecated. Is there any alternative for this?
Dilshan Liyanage
  • 4,440
  • 2
  • 31
  • 33
112
votes
6 answers

What could this be about? [TsLint Error: "Promises must be handled appropriately"]

I'm doing some basic asynchronous operations using async/await in TypeScript but TSLint is throwing mysterious error messages for these two functions below. Has anyone encountered these errors before? On the error output the governing rule is not…
cinnaroll45
  • 2,661
  • 7
  • 24
  • 41
101
votes
7 answers

How to rewrite code to avoid TSLint "object access via string literals"

I'm pretty new to TypeScript and I would like to know if there exists a good way to rewrite code to avoid TSLint error "object access via string literals is disallowed" in the following code interface ECType { name: string; type: string; …
Denis Cappellin
  • 1,230
  • 2
  • 12
  • 22
94
votes
6 answers

Why do TSLint and JSLint report empty blocks?

From time to time, I get TSLint errors "block is empty". This happens e.g. when I pass a no-op callback to a function: doSomething(() => {}); From what I read, JSLint apparently does the same, but I didn't verify that. I find these usages…
theDmi
  • 17,546
  • 6
  • 71
  • 138
91
votes
7 answers

What is the standard for use of quotes in Typescript?

I notice in my application that TsLint is suggesting: static $inject = [ '$http', '$q', '$scope', 'configService', 'stateService', 'utilityService' ]; for the above that: Message 2 TsLint: '…
Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427
89
votes
2 answers

What does it mean when TsLint says "expected callSignature to have a typedef."

I have a function in my code: networkStop = (action: string = null) => { this.action[action] = false; this.net = false; this.netd = false; } I'm getting a TsLint error saying: Message 4 TsLint: expected callSignature to have a…
user1679941
88
votes
8 answers

Disable TSLint in VSCode

So this feels like this should be such an easy task but it's starting to drive me insane. I can't seem to turn off TSLint or TS or whatever it is that gives me these errors. I just want the ESLint with my own configured rules, nothing else. Is it…
Clanket
  • 1,259
  • 2
  • 11
  • 16
1
2 3
70 71