我使用Visual Studio代码1.12.1以打字稿 2.3.2和启用插件tslint-language-service: 0.9.3与tslint: 5.2.0
由于某种原因,所有tslint提示都显示为带有红色下划线的错误.我希望将其作为绿色/黄色下划线的警告.
我该怎么做?这是我使用新的Typescript版本的插件https://github.com/angelozerr/tslint-language-service#vscode
就像在演示gif中一样,它应该是绿色而不是红色
我收到了来自 TS Lint 的警告,说我需要实现 OnInit 接口,并为我提供了一个指向此页面的链接:https : //angular.io/docs/ts/latest/guide/style-guide.html#!#09- 01
是什么区别onInit和ngOnInit。两者都为我工作。为什么可以使用,ngOnInit而不是onInit写起来很简单?
tslint no-var-keyword(“禁止的‘var’关键字”)的目的是什么?tslint 似乎在我的代码中每次出现 var 关键字时都会记录一个错误。tslint 是否说明应在 ng2 中无条件排除 var 关键字?如果是,那为什么?
为了能够在模板中使用枚举,我们在ts文件中写下面的代码.
在workflowProgress.ts中
export enum WorkflowProgress
{
cancelled = 0,
inProgress,
done
}
Run Code Online (Sandbox Code Playgroud)
在component.ts中
export class Component {
WorkflowProgress = WorkflowProgress;
x : WorkflowProgress = WorkflowProgress.done;
}
Run Code Online (Sandbox Code Playgroud)
在template.html中
<div *ngIf="x === WorkflowProgress.done">
Run Code Online (Sandbox Code Playgroud)
我们已经启用了typedef规则的tslint.但是tslint正在唠叨这条线WorkflowProgress = WorkflowProgress;
[tslint]期望成员变量声明:'WorkflowProgress'有一个typedef(typedef)
我可以通过添加禁用规则,// tslint:disable-next-line:typedef但我想知道是否有更好的方法来做到这一点?
在早期版本中,我能够将组件选择器指定为属性.
@Component({
selector: '[app-row]',
...
})
export class RowComponent implements OnInit {
ngOnInit() {}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<tr app-row></tr>
Run Code Online (Sandbox Code Playgroud)
现在我得到了lint错误:
错误:/ path/to/row.component.ts [8,13]:组件"RowComponent"的选择器应该用作元素(https://angular.io/styleguide#style-05-03)
我意识到我可以在元素中嵌入一个tr,但我并不总是能控制样式,我个人不喜欢不必要的嵌套,一般都试图避免它.
如果我应该总是使用元素选择器,如何将组件指定为"tr"元素.IE: <app-row></app-row>?什么是适当的Angular 6方法来实现这一目标?
注意:我已经查看了样式指南的链接,该部分没有涵盖与我的特定用例类似的内容.我也尝试通过id选择,但得到相同的lint错误.
我有一种情况,tslint 正在处理一些 VS Code 项目,而没有处理其他项目。它工作的项目来自带有 TypeScript 修改的create-react-app。但是当我创建一个新的 TypeScript(非 React)项目并且只是从 React 应用程序复制 tslint.json 时,tslint 不起作用(没有错误/警告 - 没有)。
这是tslint.json我用于两个应用程序的:
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
},
"rules": {
"ordered-imports": false
}
}
Run Code Online (Sandbox Code Playgroud)
这是我使用有效的 tslint 创建一个新的 TypeScript React 项目的方式:
create-react-app <app-name> --scripts-version=react-scripts-ts
Run Code Online (Sandbox Code Playgroud)
我还检查了我的 VS Code 设置,并为两个项目设置了以下内容:
"tslint.enable": true,
Run Code Online (Sandbox Code Playgroud)
tsconfig.json 对于“tslint working”项目(由 create-react-app 生成):
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react", …Run Code Online (Sandbox Code Playgroud) 我从TSLint收到此错误,并且试图了解为什么它在抱怨。
我有一个函数,该函数调用另一个返回诺言的方法,但是第一个函数不返回诺言,因为它只是等待其完成并更新内部状态。
我已将其简化为此函数,仅用于Q()模拟返回承诺的调用。
export function DoSomethingAsync(): void {
Q().then(r => {
console.log('test');
}).catch(err => {
log.error("wow");
}).finally(() => {
log.info("at finally")
});
}
Run Code Online (Sandbox Code Playgroud)
tslint现在在我的项目上运行时,出现以下错误:
错误:C:/dev/local_cache_service.ts [31,5]:必须正确处理承诺
如果我取消finally通话,tslint会顺利通过。
export function DoSomethingAsync(): void {
Q().then(r => {
console.log('test');
}).catch(err => {
log.error("wow");
});
}
Run Code Online (Sandbox Code Playgroud)
当我在种子打字稿项目上创建相同的功能时,此行为不会重现...
我正在我的 React 应用程序中导入@types/history并使用createBrowserHistory()它提供的功能。
我收到一个 tslint 错误,说
ERROR in C:/Users/eshan/my-website/src/App.tsx
ERROR in C:/Users/eshan/my-website/src/App.tsx(13,11):
typedef: expected variable-declaration: 'history' to have a typedef
Run Code Online (Sandbox Code Playgroud)
我确实环顾四周,但所有缓解这种情况的尝试似乎都是为了通过执行/* tslint:disable */. 我想添加类型支持,然后修复它。
import * as React from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import './App.css';
class App extends React.Component {
public render(): JSX.Element {
const history = createBrowserHistory();
return (
<div className='App'>
<Router history={history}>
<Switch>
<Route exact path='/' component={Landing}/>
<Route exact path='/Home' component={Home}/> …Run Code Online (Sandbox Code Playgroud) void承诺之前的实际影响是什么?
async function doAsyncStuff(){
...
}
function nonAsyncFunction(){
void doAsyncStuff();
}
Run Code Online (Sandbox Code Playgroud)
我找不到任何官方文档,但它必须在解决no-floating-promisesTSLint 错误时做一些事情。
tslint ×10
typescript ×8
angular ×4
angular6 ×1
javascript ×1
lint ×1
promise ×1
q ×1
webstorm ×1