标签: tslint

Firebase 云函数打字稿错误“并非所有代码路径都返回值”

我正在使用 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

3
推荐指数
1
解决办法
5538
查看次数

使用箭头函数而不是函数表达式 - tslint 错误

有 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)

sharepoint typescript sharepoint-online tslint

3
推荐指数
1
解决办法
1819
查看次数

为 TypeScript 文件禁用 ESLint

我有一个由遗留 JavaScript 代码(包括 eslint)和新的 TypeScript 代码(包括 tslint)组成的大型网络应用程序。

我的问题是我的 IDE (WebStorm) 会自动将两个 linter 应用于所有文件,因此在 TypeScript 中,我从 eslint 收到了我不应该收到的错误。

如何确保 eslint 仅应用于 *.js 文件而不应用于 *.ts 文件(应该只由 tslint 检查)?

lint webstorm typescript eslint tslint

3
推荐指数
2
解决办法
5954
查看次数

使用 tslint:disable 禁用代码块的 tslint 不起作用

我正在尝试为 VueJS 项目中的代码块禁用 TSlint(版本:typescript 3.5.2,tslint 5.18.0),但它似乎不起作用(它在编译时仍然显示此块的错误和警告npm 运行服务)

我已经尝试使用评论 tslint:disable 和 eslint-disable 没有成功。

谢谢你的帮助

typescript eslint vue.js tslint

3
推荐指数
1
解决办法
2958
查看次数

在 React 项目上运行“tslint --project”时,什么会产生“项目的无效选项:true”?

我正在尝试按照在线教程设置 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)

typescript reactjs tslint

3
推荐指数
1
解决办法
2530
查看次数

在 Windows 10 上,“ANY_NODE_APP”不是内部或外部命令、可运行的程序或批处理文件

我使用 Windows 10 操作系统。我已经尝试过:

npm i -g tslint
Run Code Online (Sandbox Code Playgroud)

也本地安装。

我使用可视化代码终端(power shell、git bash 和 cmd )在任何变体中都没有帮助。

tslint 的执行文件在哪里?我会将路径引入PATHenv var。

tslint visual-studio-code

3
推荐指数
1
解决办法
2487
查看次数

如何调试 angular 项目中损坏的 ng lint

在我的 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)一样调试它。

typescript tslint angular

3
推荐指数
1
解决办法
249
查看次数

如何解决无法解决对gitlab的依赖

我在 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)

dependencies gitlab tslint next.js

3
推荐指数
1
解决办法
8916
查看次数

'+' 操作的操作数必须是两个字符串或两个数字。考虑使用模板文字 @typescript-eslint/restrict-plus-operands

我只是使用 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)

如何解决这个问题。

谢谢

typescript tslint

3
推荐指数
1
解决办法
3691
查看次数

如何在 JavaScript/TypeScript 中检测具有相同索引的嵌套循环

我正在尝试检测具有相同索引的嵌套循环,如下所示:

for(let i = 0; i < 10; i++) {
    for(let i = 0; i < 10; i++) {
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经搜索了 Eslint 规则,但到目前为止还没有找到任何解决方案。有没有办法检测这种糟糕的代码味道?非常感谢。

javascript syntax-checking typescript eslint tslint

3
推荐指数
1
解决办法
71
查看次数