tslint

What is the “as syntax” pointed out by tslint?

*爱你&永不变心* 提交于 2019-11-28 00:53:14
I upgraded tslint and now it complains about: ERROR: src/Metronome/JobFetcher.ts[13, 32]: Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead. The offending code looks like: const jobs = <JobConfig[]> <any> await rp(fetchJobsOptions); What is the as syntax though and why should I use it? k0pernikus Refactor your code like this: const jobs = await rp(fetchJobsOptions) as JobConfig[]; As pointed out in the TypeScript Deep Dive book by Basarat Ali Syed , it says about type casting: as foo vs. <foo> Originally the syntax that was added was <foo> . This is demonstrated

How to ignore a particular directory or file for tslint?

人走茶凉 提交于 2019-11-27 22:38:37
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? Michael Update for tslint v5.8.0 As mentioned by Saugat Acharya , you can now update tslint.json CLI Options: { "extends": "tslint:latest", "linterOptions": { "exclude": [ "bin", "lib/*generated.js" ] } } More information in this pull request . This feature has been introduced with tslint 3.6 tslint \"src/**/*.ts\" -e \"**/__test__/**\" You can now add --exclude (or -e) see PR here. CLI usage:

Making Sense of 'No Shadowed Variable' tslint Warning

混江龙づ霸主 提交于 2019-11-27 19:18:55
问题 I have a function that checks for the current stage in a sequential stream, based on a particular discipline that is passed in, and, according to that value, assigns the next value in my Angular 2 app. It looks something like this: private getNextStageStep(currentDisciplineSelected) { const nextStageStep = ''; if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 1') { const nextStageStep = 'step 2'; } else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step

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

痴心易碎 提交于 2019-11-27 12:43:39
问题 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( this.handleUpdateResponse.bind(this), this.handleError.bind(this) ); Don't know exactly what should I use and how... Thanks! 回答1: subscribe isn't deprecated, only the variant you're using is deprecated. In the future, subscribe will only take one argument: either the

tslint / codelyzer / ng lint error: “for (… in …) statements must be filtered with an if statement”

淺唱寂寞╮ 提交于 2019-11-27 05:03:11
问题 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 field in this.formErrors) { // clear previous error message (if any) this.formErrors[field] = ''; const control = form.get(field); if (control && control.dirty && !control.valid) { const messages = this.validationMessages[field]; for (const key in control

What is the “as syntax” pointed out by tslint?

时光毁灭记忆、已成空白 提交于 2019-11-26 21:49:24
问题 I upgraded tslint and now it complains about: ERROR: src/Metronome/JobFetcher.ts[13, 32]: Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead. The offending code looks like: const jobs = <JobConfig[]> <any> await rp(fetchJobsOptions); What is the as syntax though and why should I use it? 回答1: Refactor your code like this: const jobs = await rp(fetchJobsOptions) as JobConfig[]; As pointed out in the TypeScript Deep Dive book by Basarat Ali Syed, it says about type

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

…衆ロ難τιáo~ 提交于 2019-11-26 01:23:34
问题 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 the file locally with my currently installed version of TS (1.5.3). The resulting error pointed to the exact location of the bang: $ tsc --noImplicitAny memberAccessRule.ts noPublicModifierRule.ts(57,24): error TS1005: \')\' expected. Next I upgraded