我正在使用 firebase 云功能和 firestore 交易来减少基于购买的产品的可用数量。部署时,它返回错误“错误 TS7030:并非所有代码路径都返回值”
这是代码
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore()
exports.newOrder = functions.firestore
.document('orders/{orderId}')
.onCreate(async (snap, context) => {
try {
const data = snap.data();
if (data === undefined) return null
const itemList = data.list as Array<any>
const productId: Set<string> = new Set<string>();
itemList.forEach((item) => {
productId.add(item.id)
})
return db.runTransaction(async t => {
const promises: Promise<admin.firestore.DocumentSnapshot>[] = []
productId.forEach(i => {
const p = admin.firestore().doc('Products/' + …Run Code Online (Sandbox Code Playgroud) typescript tslint google-cloud-functions google-cloud-firestore
有 tslint 警告(ES6)并且其语法仍然存在一些困难。我不知道如何转换为箭头函数。
[图像显示发生的警告][1]:https://i.stack.imgur.com/QCY69.png
var options = this.state.ProjectsArray.map(function (item, i) {
var Trmp = item["ID"] + ";#" + item["Title"];
return <option value={Trmp} key={item["ID"]}>{item["Title"]}</option> ;
});
Run Code Online (Sandbox Code Playgroud) 我有一个由遗留 JavaScript 代码(包括 eslint)和新的 TypeScript 代码(包括 tslint)组成的大型网络应用程序。
我的问题是我的 IDE (WebStorm) 会自动将两个 linter 应用于所有文件,因此在 TypeScript 中,我从 eslint 收到了我不应该收到的错误。
如何确保 eslint 仅应用于 *.js 文件而不应用于 *.ts 文件(应该只由 tslint 检查)?
我正在尝试为 VueJS 项目中的代码块禁用 TSlint(版本:typescript 3.5.2,tslint 5.18.0),但它似乎不起作用(它在编译时仍然显示此块的错误和警告npm 运行服务)
我已经尝试使用评论 tslint:disable 和 eslint-disable 没有成功。
谢谢你的帮助
我正在尝试按照在线教程设置 tslint 以处理一个小型示例 React/Typescript 项目。当我运行yarn lint或只是tslint --project在终端中输入时,我不断收到错误消息
项目选项无效:true
我做了很多谷歌搜索,我找不到我做错了什么。
我的tslint.json是
{
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
],
"rules": {
"ordered-imports": false,
"object-literal-sort-keys": false,
"no-console": false,
"jsx-no-lambda": false,
"member-ordering": false
}
}
Run Code Online (Sandbox Code Playgroud)
而我的package.json是
{
"name": "something",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "parcel ./src/index.html",
"lint": "tslint --project",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@types/react": …Run Code Online (Sandbox Code Playgroud) 我使用 Windows 10 操作系统。我已经尝试过:
npm i -g tslint
Run Code Online (Sandbox Code Playgroud)
也本地安装。
我使用可视化代码终端(power shell、git bash 和 cmd )在任何变体中都没有帮助。
tslint 的执行文件在哪里?我会将路径引入PATHenv var。
在我的 angular 应用程序中,当我运行 nglint 时,我得到了这个异常
Cannot read property 'check-regex' of undefined
[error] TypeError: Cannot read property 'check-regex' of undefined
at Rule.getRuleOptions (node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72)
at Rule.isEnabled (node_modules\tslint\lib\rules\maxLineLengthRule.js:39:26)
at Object.loadRules (node_modules\tslint\lib\ruleLoader.js:48:22)
at Linter.getEnabledRules (node_modules\tslint\lib\linter.js:232:29)
at Linter.lint (node_modules\tslint\lib\linter.js:107:33)
at _lint (node_modules\@angular-devkit\build-angular\src\tslint\index.js:146:20)
at async _run (node_modules\@angular-devkit\build-angular\src\tslint\index.js:60:29)
Run Code Online (Sandbox Code Playgroud)
有人知道如何调试吗。有没有办法像我们做代码(c#、javascript)一样调试它。
我在 GitLab CI 工作中遇到了这个问题。本地一切正常,但是当我npm install在 GitLab 上执行时,出现此错误
Running with gitlab-runner 13.5.0-rc2 (71c90c86)
on docker-auto-scale z3WU8uu-
Preparing the "docker+machine" executor
00:38
Using Docker executor with image node:latest ...
Pulling docker image node:latest ...
Using docker image sha256:ca36fba5ad66b0f8fce2b97a6f0aa53267395388ada988534d848638312ccb68 for node:latest with digest node@sha256:bf60a164bc588967ce6e3342c9d6508bf9ad2e7e2a1c237315596eab3e13428b ...
Preparing environment
00:03
Running on runner-z3wu8uu--project-17807115-concurrent-0 via runner-z3wu8uu--srm-1603491340-e6ca0bf8...
Getting source from Git repository
00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/DreamStartLabs/save/save-plus-web/.git/
Created fresh repository.
Checking out …Run Code Online (Sandbox Code Playgroud) 我只是使用 tslint 但这块代码给我一个错误。
const MemberNumber = 'MBR' + pinCode + sliceNumber
Run Code Online (Sandbox Code Playgroud)
Operands of '+' operation must either be both strings or both numbers. Consider using a template literal @typescript-eslint/restrict-plus-operands
Run Code Online (Sandbox Code Playgroud)
我厌倦了模板方法再次抛出 tslint 错误。
const MemberNumber = `MBR${pinCode}${sliceNumber}`
Run Code Online (Sandbox Code Playgroud)
Invalid type "any" of template literal expression @typescript-eslint/restrict-template-expres
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题。
谢谢
我正在尝试检测具有相同索引的嵌套循环,如下所示:
for(let i = 0; i < 10; i++) {
for(let i = 0; i < 10; i++) {
}
}
Run Code Online (Sandbox Code Playgroud)
我已经搜索了 Eslint 规则,但到目前为止还没有找到任何解决方案。有没有办法检测这种糟糕的代码味道?非常感谢。
tslint ×10
typescript ×8
eslint ×3
angular ×1
dependencies ×1
gitlab ×1
javascript ×1
lint ×1
next.js ×1
reactjs ×1
sharepoint ×1
vue.js ×1
webstorm ×1