简体   繁体   English

条件类型。 来自 TypeScript eslint 的解析错误

[英]Conditional Types. Parsing error from TypeScript eslint

I get an eslint error when I try the following implementation in typescript.当我在 typescript 中尝试以下实现时,出现 eslint 错误。

type CamelToSnakeCase<S extends string> =
  S extends `${infer T}${infer U}` ?
  `${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${CamelToSnakeCase<U>}` : S

I get the following error on vscode我在 vscode 上收到以下错误

Parsing error: Type expected.eslint解析错误:键入 expected.eslint

my.eslint.js我的.eslint.js

   module.exports = {
      root: true,
      env: {
        es6: true,
        node: true,
      },
      extends: [
        "eslint:recommended",
        "plugin:import/errors",
        "plugin:import/warnings",
        "plugin:import/typescript",
        "google",
        "plugin:@typescript-eslint/recommended",
      ],
      parser: "@typescript-eslint/parser",
      parserOptions: {
        project: [
          "tsconfig.json",
          "tsconfig.dev.json",
        ],
        sourceType: "module",
      },
      ignorePatterns: [
        "/lib/**/*", // Ignore built files.
      ],
      plugins: [
        "@typescript-eslint",
        "import",
      ],
      rules: {
        "quotes": ["error", "double"],
        "import/no-unresolved": 0,
      },
    };

This may be a rudimentary question, but please answer.这可能是一个初级问题,但请回答。

Template literal are supported from Typescript 4.1 onwards.从 Typescript 4.1 开始支持模板文字

You'll need to update your TS version !您需要更新您的 TS 版本!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM