0

I get an eslint error when I try the following implementation in typescript.

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

Parsing error: Type expected.eslint

my .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.

1
  • Exactly what part is highlighted by the error? Does the error have any additional details? Commented Aug 3, 2022 at 21:09

1 Answer 1

1

Template literal are supported from Typescript 4.1 onwards.

You'll need to update your TS version !

Sign up to request clarification or add additional context in comments.

1 Comment

I see! Thanks, I checked package-lock.json and it says "typescript": "3.9.10". I really appreciate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.