我需要对接口或类型内的属性使用 Snake_case。我设定camelcase规则
'camelcase': ["error", {properties: "never"}],
Run Code Online (Sandbox Code Playgroud)
正如文档中提到的。它不适用于接口和类型,但适用于 JS 对象。
export const test = {
a_b: 1, // OK. No error
};
export interface ITest {
a_b: number, // Identifier 'a_b' is not in camel case.eslint(camelcase)
}
export type TTest = {
a_b: number, // Identifier 'a_b' is not in camel case.eslint(camelcase)
}
Run Code Online (Sandbox Code Playgroud)
当我将规则设置为 时,错误消失'off',因此此规则适用于 .ts 文件。
那么如何在TS中使用snake_case呢?谢谢。
我有这个代码:
\nconst expressionAttributeValues = {};\nexpressionAttributeValues[`:${status}`] = status; // TSLinst error\n// status is a string\nRun Code Online (Sandbox Code Playgroud)\n我收到了 TSlint 错误:
\n TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. \xc2\xa0\xc2\xa0No index signature with a parameter of type 'string' was found on type '{}'.\nRun Code Online (Sandbox Code Playgroud)\n这行有什么问题吗?
\n确保我的TypeScript和相应的JavaScript文件中只有ASCII字符的最佳方法是什么?
我正在为angular2项目使用angular cli.虽然我使用lint命令进行linting-and-formatting-code,如下所示
ng lint
Run Code Online (Sandbox Code Playgroud)
我可以在命令提示符下看到几个错误,如下所示
src/app/quote/your-cart/your-cart.component.ts[118, 9]: missing whitespace
src/app/quote/your-cart/your-cart.component.ts[129, 8]: missing whitespace
src/app/quote/your-cart/your-cart.component.ts[130, 9]: missing whitespace
src/app/quote/your-cart/your-cart.component.ts[142, 21]: missing whitespace
Run Code Online (Sandbox Code Playgroud)
由于它报告了大量错误,我想在某个文件上导出该错误.它可能是HTML,TXT,甚至JSON也没关系.
简而言之,我想将角度cli lint错误导出到某个文件.
请帮忙.
我收到这个tslint错误,我不明白为什么。该界面确实以大写字母开头。
29 col 11 error| interface name must start with a capitalized I (interface-name) [typescript/tslint]
S> 29 interface Props {
30 answerQuestion: (answerQuestion: AnswerQuestion) => void;
Run Code Online (Sandbox Code Playgroud) 我在Vue类组件中使用道具。道具是在构造函数中定义的,没有值。这可以编译并正常工作,但是由于最新的VS Code / TSLint更新,我收到以下警告:
属性“标签”没有初始化程序,并且在构造函数中未明确分配。
Vue类组件
export default class Browser extends Vue {
@Prop({default: '', required:false})
tag: string
created(){
console.log("the tag prop is " + this.tag)
}
}
Run Code Online (Sandbox Code Playgroud)
如果我确实分配它,则会收到Vue警告,提示您不应在子组件中操纵Prop。
[Vue警告]:避免直接更改prop,因为每当父组件重新渲染时,该值都会被覆盖
由于这似乎主要是棉绒问题,有没有办法禁用它?还是我的代码实际上是错误的?
运行“ng serve”时出现以下错误。
TypeScript 编译中缺少 node_modules/angular2-indexeddb/index.ts。请通过“文件”或“包含”属性确保它在您的 tsconfig 中。丢失的文件似乎是第三方库的一部分。已发布库中的 TS 文件通常是库打包不当的标志。请在库存储库中打开一个问题以提醒其作者并要求他们使用 Angular 包格式 ( https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview )打包库。
我想问题是 angular2-indexeddb 没有被 tsconfig 编译。 https://github.com/gilf/angular2-indexeddb
我认为应该通过在 tslint.json 中编辑以下配置来临时解决,但我需要一个解决方案来解决它。
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
Run Code Online (Sandbox Code Playgroud)
是不是因为angular2-indexeddb 没有提供好的打包库?事实上,我认为流行的已发布图书馆不应该有这个问题。或者我错过了配置或编译的东西?我可以使用包编译工具/库将其编译成 d.ts 或 spec.ts 吗?
事实上,我在目录中看到了 *.d.ts 文件:
ls node_modules/angular2-indexeddb/
LICENSE angular2-indexeddb.metadata.json index.js
README.md angular2-indexeddb.min.js index.js.map
angular2-indexeddb.d.ts angular2-indexeddb.min.js.map index.ts
angular2-indexeddb.js angular2-indexeddb.ts package.json
angular2-indexeddb.js.map index.d.ts
Run Code Online (Sandbox Code Playgroud)
tsconfig.json 中的内容:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": …Run Code Online (Sandbox Code Playgroud) 我使用更漂亮的tslint和https://github.com/alexjoverm/tslint-config-prettier和https://github.com/ikatyang/tslint-plugin-prettier。
我tslint.json就像
{
"defaultSeverity": "error",
"extends": [
"tslint-config-airbnb",
"tslint-react",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {
"max-line-length": [true, 80],
"import-name": false,
"variable-name": false,
"jsx-boolean-value": false,
"jsx-no-multiline-js": false,
"no-else-after-return": false,
"object-shorthand-properties-first": false,
"ter-arrow-parens": false,
"ter-indent": false,
"prettier": true
},
"rulesDirectory": ["tslint-plugin-prettier"]
}
Run Code Online (Sandbox Code Playgroud)
而我.prettierrc就像
{
"trailingComma": "all",
"singleQuote": true
}
Run Code Online (Sandbox Code Playgroud)
之后tslint --fix "src/**/*.ts",出现如下代码:
import { getChildrenProceduresSelector } from '@src/entities/procedures/selectors';
Run Code Online (Sandbox Code Playgroud)
错误说[tslint] Exceeds maximum line length of 80 (max-line-length)。
但是当我手动修复它
import {
getChildrenProceduresSelector, …Run Code Online (Sandbox Code Playgroud) 我正在使用VSCode,Prettier和TSLint。
当我确实有多个函数调用时,例如
let m = moment().startOf("day").subtract(30, "days");
Run Code Online (Sandbox Code Playgroud)
更漂亮的闯入
let m = moment()
.startOf("day")
.subtract(30, "days")
Run Code Online (Sandbox Code Playgroud)
我已经设置了TSLint规则
{
"defaultSeverity": "warning",
"extends": ["tslint:recommended"],
"linterOptions": {
"exclude": ["node_modules/**"]
},
"rules": {
// ...
"newline-per-chained-call": false
}
}
Run Code Online (Sandbox Code Playgroud)
和休闲的设置
"prettier.tslintIntegration": true
Run Code Online (Sandbox Code Playgroud)
但是链接的功能仍在不断发展。
如何避免断线但仍使用TSLint?
eslint添加了打字稿检查后,当类定义中的属性变量为Array时将出现错误。



这是我的eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
'extends': ['plugin:vue/essential', '@vue/standard'],
rules: {},
parserOptions: {
parser: '@typescript-eslint/parser',
project: "./tsconfig.json"
},
plugins: ['@typescript-eslint']
};
Run Code Online (Sandbox Code Playgroud) tslint ×10
typescript ×7
javascript ×3
angular ×2
eslint ×2
prettier ×2
angular-cli ×1
indexeddb ×1
tsconfig ×1
vue.js ×1