在我的 settings.json 中,我有:
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
Run Code Online (Sandbox Code Playgroud)
然而我的打字稿支持不起作用。它在运行时捕获错误,但不显示红色波浪线(下面的示例)。
启用 ESLint 时我也会收到错误,并且当我启用 ESLint 时 Prettier 不起作用:
ESLint: Failed to load parser '@typescript-eslint/parser' declared in 'template/.eslintrc.js': Cannot find module 'typescript' Require stack: - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/typescript-estree/dist/parser.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/typescript-estree/dist/index.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/parser/dist/parser.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/parser/dist/index.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/config-array-factory.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/cli-engine.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/index.j
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
npx ng lint <projectName>
> nx run <projectName>:lint
'tsConfig' is not found in schema
Run Code Online (Sandbox Code Playgroud)
我曾经做过从 tslint 到 eslint 的迁移。我关注了这篇文章: https ://code.visualstudio.com/api/advanced-topics/tslint-eslint-migration
我不知道为什么会出现这个错误。
有人可以帮忙吗?
面对TS的奇怪行为。
const isItLanding = false;
if (isItLanding === undefined) { // valid
return ...;
}
Run Code Online (Sandbox Code Playgroud)
但在这儿
const isItLanding = 1;
if (isItLanding === 'undefined') { // error
return ...;
}
Run Code Online (Sandbox Code Playgroud)
为什么 TS 不保证不会写入无效比较?我怎样才能改变这种行为?
我的 TS 配置如下:
{
"compilerOptions": {
"strict": true,
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"importsNotUsedAsValues": "error",
"allowSyntheticDefaultImports": true,
"incremental": true,
"tsBuildInfoFile": ".next/cache/.tscache/",
"jsx": "preserve",
"sourceMap": true,
"baseUrl": ".",
"paths": …Run Code Online (Sandbox Code Playgroud) 我正在使用tslint:recommended规则集编写Node.js应用程序,它警告我console.log在我的代码中使用:
src/index.ts[1, 1]: Calls to 'console.log' are not allowed.
Run Code Online (Sandbox Code Playgroud)
我还应该使用什么?我应该使用某种system.out等价物吗?
这是我的tslint.json:
{
"extends": "tslint:recommended"
}
Run Code Online (Sandbox Code Playgroud) 这是我们的环境
> \node_modules\.bin\tslint --version
4.0.1
> npm install --save-dev tslint-microsoft-contrib
`-- tslint-microsoft-contrib@2.0.13
Run Code Online (Sandbox Code Playgroud)
这是我们的tslint.json配置.
{
"extends": [
"./node_modules/tslint-microsoft-contrib/tslint.json"
]
}
Run Code Online (Sandbox Code Playgroud)
当我们tslint使用该配置运行本地时会发生这种情况.
> node_modules\.bin\tslint --config .\tslint.json --project .\tsconfig.json
module.js:471
throw err;
^
Error: Cannot find module 'tslint/lib/lint'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\myApp\node_modules\tslint-microsoft-contrib\insecureRandomRule.js:7:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Run Code Online (Sandbox Code Playgroud)
我们如何运行tslint扩展的配置tslint-microsoft-contrib?
与我关于as-syntax的问题相关,我想查找tslint规则以找出问题所在.唉,我只看到我的tslint运行的错误信息,如下所示:
ERROR: src/Metronome/JobFetcher.ts[13, 32]: Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead.
ERROR: src/Metronome/JobConfig.ts[20, 1]: Consecutive blank lines are forbidden
ERROR: src/Metronome/JobFetcher.ts[7, 23]: ' should be "
Run Code Online (Sandbox Code Playgroud)
这里缺少的是导致该错误的规则.例如,我知道这条线' should be "与quotemark我的规则有关tsconfig.json:
"quotemark": [
true,
"double",
"avoid-escape"
],
Run Code Online (Sandbox Code Playgroud)
然而我不知道对于其他规则而且因为我依赖于我tslint:recommended的大部分配置,一旦发生错误我就很难查找它我以前没见过,就像as语法一样,我只能通过谷歌搜索as语法,而不是通过tslint的参考文档解决.
如何知道我的tslint配置的哪些规则导致错误消息?
在我的Ionic 3项目中,我似乎得到了很多误报:
这是正常的吗?
12:27:29] tslint:src/pages/tabs/tabs.ts,line:28属性'navParams'已声明但从未使用过.
L27: constructor(
L28: private navParams: NavParams,
L29: @Inject(forwardRef(() => AuthService ))
Run Code Online (Sandbox Code Playgroud)
[12:27:29] tslint:src/pages/tabs/tabs.ts,line:30属性'authService'已声明但从未使用过.
L29: @Inject(forwardRef(() => AuthService ))
L30: private authService:AuthService
L31: ) {
Run Code Online (Sandbox Code Playgroud)
然而,这是代码:
export class TabsPage {
...
mySelectedIndex: number;
loggedIn:boolean;
constructor(
private navParams: NavParams,
@Inject(forwardRef(() => AuthService ))
private authService:AuthService
) {
console.log('TabsPage constructor: navParams.data: ', navParams.data);
this.loggedIn = authService.authenticated(RootPage.LAUNCHPAD.toString());
this.mySelectedIndex = navParams.data.tabIndex || 0;
console.log('Tabs pages: selectedIndex: ' + this.mySelectedIndex);
console.log('Tabs pages: loggedIn: ' + this.loggedIn);
}
isLoggedIn():boolean {
return this.loggedIn; …Run Code Online (Sandbox Code Playgroud) 好像我不知道字母表.请告诉我这里没有订购:
import * as React from 'react';
import {
Badge,
Button,
ButtonGroup,
Collapse,
Dropdown,
DropdownItem,
DropdownMenu,
DropdownToggle,
Input,
InputGroup,
InputGroupAddon,
Nav,
Navbar,
NavbarBrand,
NavItem,
NavLink,
UncontrolledAlert,
} from 'reactstrap';
import {logoutUser} from '../actions/user';
import {positionSidebar,toggleSidebar,toggleVisibilitySidebar} from '../actions/navigation';
import s from './Header.scss';
import sender1 from '../../images/1.png';
import sender2 from '../../images/2.png';
import sender3 from '../../images/3.png';
Run Code Online (Sandbox Code Playgroud)
它在第22行给出了错误:"组内的导入源必须按字母顺序排列." (导入{positionSidebar ....)但他们是正确的订购!! (或许我必须回到学校:().
我试图禁用这个愚蠢的字母顺序:但我不能:
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"ordered-imports": [true, {
"import-sources-order": "any",
"named-imports-order": "any",
"grouped-imports": false,
"module-source-path": "basename"
}]
Run Code Online (Sandbox Code Playgroud)
这不起作用,错误重复.我会在github上发布它,但有很多关于这个的帖子,也许这不是一个bug.如果你认为它是bug,请告诉我,我会在那里发布.
我的tslint进口:
"tslint": "^5.7.0",
"tslint-config-prettier": …Run Code Online (Sandbox Code Playgroud) 在尝试构建我的Angular 6应用程序时,我遇到了以下错误.
src/app/util/notification.service.ts(14,9)中的错误:错误TS1005:':'预期.
这是相关的代码
import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
@Injectable()
export class NotificationService {
timeOut: number = 5000;
constructor(private toastr: ToastrService) {}
error(toast_msg, msg_title){
this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, {
this.timeOut
});
}
}
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?
我刚刚编写了下面的循环,效果很好:
let position = 0;
// tslint:disable-next-line:no-conditional-assignment
while ((position = source.indexOf('something interesting', position)) > 0) {
// do something interesting with something interesting
position += 1;
}
Run Code Online (Sandbox Code Playgroud)
但是请注意,我必须添加tslint例外。显然,有人决定不希望在while条件内包含赋值语句
。但是,对于这种特殊情况,这是我所知道的最直接的代码模式。
如果这不是“允许的”(或者我应该说“受挫的”),那么推动这一工作的人们认为正确的代码模式是什么?