tslint

How to rewrite code to avoid TSLint “object access via string literals”

醉酒当歌 提交于 2019-11-30 02:39:27
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; elementType?: string; } export var fields: { [structName: string]: Array<ECType>; } = { }; class ECStruct1 { foo: string; bar: number; baz: boolean; qux: number; quux: number; corge: ECStruct2[]; grault: ECStruct2; constructor() { ... } } fields['ECStruct1'] = [ { name: 'foo', type: 'string' }, { name: 'bar', type: 'int' }, { name: 'baz', type: 'bool' }, {

How to lint entire folder using tslint

…衆ロ難τιáo~ 提交于 2019-11-29 22:47:10
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 examples on the site - they show how to validate single file, which is not the case usually. Is that possible to validate my project without extra things like gulp-tslint , just from the command line? You can use a glob to lint multiple files. Normally, if you just pass a glob as is, your shell will expand it and pass the resulting files to TSLint. So

Is there a way to enforce method return types on Typescript classes via a tslint rule?

老子叫甜甜 提交于 2019-11-29 16:29:54
问题 I've read the tslint rules here and while it looks like the typedef rule's call-signature option is what I want, it doesn't complain about the lack of a return type. Anyone know the rule (f one exists) to enforce return types on class methods? 回答1: Turns out this can be done via: "typedef": [ true, "call-signature", "property-declaration" ] More info: https://palantir.github.io/tslint/rules/typedef/ 来源: https://stackoverflow.com/questions/42793701/is-there-a-way-to-enforce-method-return-types

How to lint for Typescript compilation issues?

吃可爱长大的小学妹 提交于 2019-11-29 13:37:24
Take the following Typescript arrow function: /** * Returns a probably unique component name. * * @param baseName a suggested name to make unique. * @returns a probably unique name. */ export const getUniqueComponentName = ( baseName ): string => { return baseName + Math.round(Math.random() * 10000000) } When Typescript is configured in tsconfig.json as such: "noImplicitAny": true, This correctly results in a compilation error: [ts] Parameter 'baseName' implicitly has an 'any' type. Visual Studio Code is also smart enough to inform you about this issue during development. My goal is to create

What is the tslint blacklist and why does angular-cli default rxjs on the list in tslint.json?

别来无恙 提交于 2019-11-29 13:22:06
By default with an angular-cli project the tslint settings come packed with things that go squiggle. I recently was approached by a new developer that I had configure their tslint instance in Atom. I was asked about the following line: import { Observable, BehaviorSubject } from 'rxjs'; The TSLinter is saying that rxjs is blacklisted. I went to the tslint.json file and, sure enough, it was listed. What is this blacklist and does it protect the app from something? Why is rxjs added to the list by default? Under what conditions should I be adding something else to it? I'd like to point out that

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

坚强是说给别人听的谎言 提交于 2019-11-29 04:37:19
问题 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 mentioned, so I don't understand what's causing these. Any ideas would be greatly appreciated. The main request: import * as rp from 'request-promise' export function getRequest(address: rp.Options): rp.RequestPromise { return rp(address) } Exported

Set up TSLint for VS2017

廉价感情. 提交于 2019-11-29 04:16:46
问题 I have tried to install this plugin: Web Analyzer, but unfortunately it can not be installed in VS 2017. It showed: VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products. I am wondering whether there is a way to set up tslint in VS or there is any other way to check the syntax? 回答1: Now that TypeScript has language server plugins support and there's TSLint plugin, another option is available: Install Visual Studio 2017 Update 2 Install

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

本小妞迷上赌 提交于 2019-11-28 15:36:22
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.errors) { this.formErrors[field] += messages[key] + ' '; } } } Any idea how to fix this lint error? A

Making Sense of 'No Shadowed Variable' tslint Warning

狂风中的少年 提交于 2019-11-28 10:43:00
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 2') { const nextStageStep = 'step 3'; } else if (this.stageForDiscipline(this.currentDisciplineSelected

What is the tslint blacklist and why does angular-cli default rxjs on the list in tslint.json?

只谈情不闲聊 提交于 2019-11-28 07:13:34
问题 By default with an angular-cli project the tslint settings come packed with things that go squiggle. I recently was approached by a new developer that I had configure their tslint instance in Atom. I was asked about the following line: import { Observable, BehaviorSubject } from 'rxjs'; The TSLinter is saying that rxjs is blacklisted. I went to the tslint.json file and, sure enough, it was listed. What is this blacklist and does it protect the app from something? Why is rxjs added to the list