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

992 questions
698
votes
3 answers

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

When looking at the sourcecode 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
  • 29,972
  • 27
  • 103
  • 151
263
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…
choopage - Jek Bao
  • 4,915
  • 5
  • 29
  • 59
209
votes
9 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…
user1186050
  • 10,710
  • 18
  • 92
  • 235
200
votes
4 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?
garrettmaring
  • 4,580
  • 2
  • 20
  • 39
179
votes
7 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 an angular 7 app with angular-cli): this.userService.updateUser(data).pipe( tap(() => {bla bla bla}) ).subscribe( …
ismaestro
  • 5,270
  • 6
  • 31
  • 45
151
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
  • 3,021
  • 5
  • 18
  • 30
114
votes
9 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
  • 4,099
  • 6
  • 32
  • 52
91
votes
9 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
  • 4,099
  • 6
  • 32
  • 52
90
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,090
  • 1
  • 10
  • 18
86
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,151
  • 3
  • 19
  • 33
85
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
  • 3,382
  • 1
  • 24
  • 27
79
votes
3 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
76
votes
6 answers

Auto fix TSLint Warnings

[64, 1]: space indentation expected [15, 27]: Missing semicolon [109, 36]: missing whitespace [111, 24]: missing whitespace [70, 1]: Consecutive blank lines are forbidden I keep getting warnings like these from TSLint. There…
ANKIT HALDAR
  • 1,275
  • 1
  • 8
  • 16
73
votes
4 answers

Angular2 - HTTP RequestOptions HEADERS

I currently have an issue with tslint and was hoping someone could point me in the right direction. I'm trying to send an HTTP GET request using HTTP provided by the Angular2 framework. With this request, I must specify the content-type and the…
Zander17
  • 1,634
  • 5
  • 17
  • 29
71
votes
3 answers

How to lint entire folder using tslint

Is that possible to lint entire folder using tslint? Using eslint it is possible to do eslint ./src to validate whole folder. When i try to do the same for tslint - i am getting an error Error: EISDIR: illegal operation on a directory. In their…
ValeriiVasin
  • 8,240
  • 11
  • 53
  • 75
1
2 3
66 67