标签: tslint

在Visual Studio 2015中设置TSLint

我在Visual Studio 2013中使用Typescript开发,并始终在底部打开我的错误列表.TSLint告诉我,当我编写代码时,我的代码很乱/不正确.除了安装Web Essentials插件之外,我认为我不必做任何其他事情.

我最近安装了Visual Studio 2015,但在我的生活中,不能像在Visual Studio 2013中那样使用TSLint.我是否遗漏了一些明显的东西?

tslint visual-studio-2015

16
推荐指数
2
解决办法
9258
查看次数

使用webpack 2.1.0-beta.25的tslint-loader

我有一个angular2项目,我用webpack压缩/编译.

我使用tspack loader和webpack,所以我有tslint相关的配置webpack.config.js.

module.exports = {
...
tslint: {
    configuration: {
        rules: {
            quotemark: [true, "double"]
        }
    },

    // tslint errors are displayed by default as warnings
    // set emitErrors to true to display them as errors
    emitErrors: false,

    // tslint does not interrupt the compilation by default
    // if you want any file with tslint errors to fail
    // set failOnHint to true
    failOnHint: true,

    // name of your formatter (optional)
    formatter: "",

    // path to directory …
Run Code Online (Sandbox Code Playgroud)

typescript webpack tslint webpack-2

16
推荐指数
1
解决办法
2万
查看次数

不要使用对象作为类型

我收到 lint 错误:

不要使用对象作为类型

当我使用对象作为类型时,示例如下:

export const myFunc = (obj: object): string => {
  return obj.toString()
}
Run Code Online (Sandbox Code Playgroud)

知道我应该为具有未知属性的对象赋予什么类型吗?

如果有帮助的话,有问题的对象不是一个数组(我知道它严格来说是 JS 中的一个对象)

提前致谢

typescript eslint tslint

16
推荐指数
2
解决办法
1万
查看次数

tslint中的"no-string-literal"规则是什么?

这里的描述非常简短:

禁止通过字符串文字访问对象.

还有其他文档或示例吗?

typescript tslint

15
推荐指数
1
解决办法
4658
查看次数

TSLint不在VS Code中工作

我使用tslint VSCode扩展将TSLint添加到我的React/TypeScript项目中.我还根据TSLint文档全局安装了typescript和tslintnpm install -g tslint typescript

这是我的tslint.json文件:

{
  "extends": ["tslint:latest", "tslint-react"],
  "rules": {
    // override tslint-react rules here
    "jsx-wrap-multiline": false,
    "max-line-length": false,
    "no-implicit-dependencies": [true, "dev"],
    "no-var-requires": false,
    "indent": false
  }
}
Run Code Online (Sandbox Code Playgroud)

lint typescript tslint visual-studio-code

15
推荐指数
1
解决办法
2万
查看次数

如何解决不是所有代码路径都返回值的问题?

我在尝试解决的代码中有错误。我认为它需要一个return语句,但我已经在forEach循环之外,但它仍然抛出错误:

not all the code path return the value
Run Code Online (Sandbox Code Playgroud)

如何修复下面的代码?

main.ts

private ValidateRequestArgs(str) {
  let ret: boolean = true;
  // here on val its throwing tslint error not all code paths return value 
  str.split(',').forEach((val) => {
    if (!ret) {
      return false;
    }
    if (List.indexOf(val) > -1) {
      ret = true;
    } else {
      ret = false;
    }
  });
  return ret;
}
Run Code Online (Sandbox Code Playgroud)

javascript typescript tslint

15
推荐指数
5
解决办法
3万
查看次数

TypeScript linter警告:不推荐使用no-unused-variable;但我没有使用此配置

今天,我在3个月后刷新的项目中看到此警告。

不推荐使用未使用的变量。从TypeScript 2.9开始。请改用内置的编译器检查。

但是我tsconfig.json似乎没有使用它。

{
  "compilerOptions": {
    "lib": ["es6"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6",
    "allowJs" : true
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}
Run Code Online (Sandbox Code Playgroud)

可能是以前任何配置中都隐含的配置。

您能指出我该怎么做吗?

如果有用

$ node -v
v10.3.0
$ npm -v
6.1.0
Run Code Online (Sandbox Code Playgroud)

这些devDependencies与我的类型脚本有关package.json

"devDependencies": {
    ...
    "tslint": "^5.11.0",
    "typescript": "^2.9.1"
    ...
  },
Run Code Online (Sandbox Code Playgroud)

typescript tslint

15
推荐指数
3
解决办法
5248
查看次数

是否可以在Visual Studio 2015中配置TSLint?

TSLint抱怨单引号应该是双引号.我们的团队更喜欢使用单引号来包装字符串文字.

我看到TSLint可配置为将模式设置为单引号,但我找不到在Visual Studio 2015中设置这些规则的方法.

在Options中,我在Text Editor> TypeScript> TSLint下找到了几个TSLint选项:

  • 启用TSLint
  • 警告为错误

显然,这些不是我正在寻找的设置......

有没有人找到在Visual Studio 2015中配置TSLint规则的方法,或者这是我们不得不希望它们在不久的将来添加的东西?


此解决方案:在Visual Studio 2015中设置TSLint

似乎只是将TSLint添加到Visual Studio 2015(如果它尚不存在).这不是我正在寻找的.

typescript tslint visual-studio-2015

14
推荐指数
2
解决办法
4580
查看次数

TSLint 正在被弃用。这对 Angular 有何影响?

我工作的公司即将启动一个新的企业 Angular 应用程序。在阅读linting 时,我读到TSLint 正在被弃用

由于 TSLint 默认包含在 Angular 中,我开始寻找 Angular 团队必须处理弃用的任何计划。我发现了这个 GitHub 问题,这不是很有帮助。它指向我这里,我找不到任何与该问题相关的帖子。

我的问题是:

  1. 作为 Angular 开发人员,我是否应该为新项目和/或现有项目手动迁移到 Typescript ESLint?
  2. Angular 团队是否有任何计划让现有项目的最终迁移更容易?

tslint angular typescript-eslint

14
推荐指数
1
解决办法
5016
查看次数

Angular 11:订阅已弃用:改用观察者?

我的 tslint 疯了吗?它为我在整个应用程序中所做的每个订阅发出警告。无论我使用旧的还是新的语法都没有关系,它仍然说 subscribe 已被弃用......如何编写一个不会被弃用的订阅?

直到今天还好:

something.subscribe((user: User) => {
        this.userProviderService.setUserId(user.userId);
        this.proceed = true;
      });
Run Code Online (Sandbox Code Playgroud)

我尝试了新语法但没有改变:

something.subscribe({
        next: (user: User) =>  {
          this.userProviderService.setUserId(user.userId);
          this.proceed = true;
        },
        complete: () => {},
        error: () => {}
      });
Run Code Online (Sandbox Code Playgroud)

这正是它所说的:

(方法) Observable.subscribe(next?: (value: Object) => void, error?: (error: any) => void, complete?: () => void): Subscription (+4重载) @deprecated —使用观察者而不是完整的回调

@deprecated — 使用观察者而不是错误回调

@deprecated — 使用观察者而不是完整的回调

订阅已弃用:使用观察者而不是完整的回调(弃用)tslint(1)

那么我现在如何订阅东西?

typescript tslint angular

14
推荐指数
3
解决办法
7475
查看次数