小编 Hi*_*bo 的帖子

Typescript / Eslint 在我启动的每个项目中都会抛出“无法读取文件 tsconfig.json”

在其他线程中,我读到当 eslint 和 tsconfig.json 不在同一工作文件夹中时可能会出现问题,但我在项目的根文件夹中拥有所有文件。不知何故,初始化项目后,抛出的错误似乎尝试在项目的父文件夹中(因此,在项目外部)查找 tsconfig.json:

假设项目位于:'\parentFolder\ProjectRoot' tsconfig 位于路线中:'\parentFolder\ProjectRoot\tsconfig.json

我得到的 eslint 错误(位于 index.ts 的顶部)如下:

解析错误:无法读取文件“ parentFolder \tsconfig.json”

  • 请注意,eslint 以某种方式在错误的文件夹(根文件夹的父文件夹)中查找 tsconfig


\parentFolder\ProjectRoot 的内容是:

达到这一点的步骤是:

  • npm 初始化
  • npm i-D 打字稿
  • 将 "tsc": "tsc" 脚本添加到 package.json
  • npm 运行 tsc -- --init
  • npm 我表达
  • npm i -D eslint @types/express @typescript-eslint/eslint-plugin @typescript-eslint/parser
  • npm i -D ts-node-dev

.eslintrc:

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "plugins": ["@typescript-eslint"],
  "env": {
    "browser": true,
    "es6": true
  },
  "rules": {
    "@typescript-eslint/semi": ["error"],
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-unused-vars": [
        "error", { "argsIgnorePattern": …
Run Code Online (Sandbox Code Playgroud)

node.js express typescript eslint

31
推荐指数
3
解决办法
3万
查看次数

TypeScript/Eslint 在 Express Router 异步路由上抛出“Promise returned”错误

我有以下端点设置来在测试运行后重置数据库:

import { getConnection } from 'typeorm';
import express from 'express';
const router = express.Router();

const resetDatabase = async (): Promise<void> => {
  const connection = getConnection();
  await connection.dropDatabase();
  await connection.synchronize();
};

// typescript-eslint throws an error in the following route:
router.post('/reset', async (_request, response) => {
  await resetTestDatabase();
  response.status(204).end();
});

export default router;
Run Code Online (Sandbox Code Playgroud)

此后的整个路线都async带有下划线,并带有 typescript-eslint 错误Promise returned in function argument where a void return was expected.

该应用程序工作完美,但我不确定我是否应该执行更安全的实现,或者只是忽略/禁用此应用程序的 Eslint。知道该代码有什么问题吗?

node.js typescript eslint typeorm express-router

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

如何通过 TypeScript 使用 Apollo 客户端自定义挂钩?

我正在尝试在 TypeScript 项目中创建以下形状的自定义 Apollo Client 突变挂钩:

const customApolloMutation = () => {

  const [
    mutationFunction,
    { data, loading, error, ...result } // or just {...result}
  ] = useMutation(GRAPHQL_QUERY)


  return [mutationFunction,
    { data, loading, error, ...result } // or just {...result}
  ]
}

export default customApolloMutation ;
Run Code Online (Sandbox Code Playgroud)

一切看起来都很好,但是当我在不同的文件中导入自定义挂钩时,如下所示:

  const [mutationFunction, {data, loading, error}] = customApolloMutation();
Run Code Online (Sandbox Code Playgroud)

...所有解构的 props 都会给出 TypeScript 错误,例如Property 'loading' does not exist on type '((options?: MutationFunctionOptions<any, OperationVariables> | undefined) => Promise<FetchResult<any, Record<string, any>, Record<string, any>>>) | { ...; …

hook typescript apollo-client react-hooks react-apollo-hooks

6
推荐指数
1
解决办法
1686
查看次数

Cypress:如何测试 HTML5 内置验证弹出窗口?

在使用 Cypress 测试应用程序时,我们如何捕获 HTML5 内置的弹出验证错误?它似乎没有出现在 DOM 中,所以我不知道如何用命令捕获它cy(我正在使用testing-library)。

在此输入图像描述

html testing validation cypress react-hook-form

5
推荐指数
1
解决办法
1477
查看次数

VS Code 模板字符串 css 语法高亮?(情感)

如何template string css在 VS Code 中启用情感语法突出显示?我找到的所有插件都是用于片段的。

它可以工作,css({ camelCaseCssProps:...})但我试图css variables在没有导入的情况下使用主题,我想一般来说我宁愿kebab-case在我的全局样式文件中保留常规的 css 语法:

// index.js
    
render(
  <Global
    styles={css`
      html {
        // css variables (and/or camel-case props)
        --color-base: white;
        --color-text: #434449;
       }
    `}
  />
)
Run Code Online (Sandbox Code Playgroud)

css syntax-highlighting emotion visual-studio-code styled-components

5
推荐指数
1
解决办法
2816
查看次数