1

I have this type:

export type ICfnOutput = {
    ENDPOINTS: {
        [key in `${keyof typeof MSERVICES}_ENDPOINT`]: string
    },
    USER_POOL_CLIENT_ID: string,
    amplifyClientUrl: string,
    USER_POOL_ID: string
}

When I run the command:

eslint .  --ext .ts

I get the following error:

error  Parsing error: Type expected

.eslintrc.json

{
    "env": {
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {}
}

Im using eslint v8.21.0, how can I avoid this, or should I ignore it and add an ignore command because seems to be an eslint problem

The code is working fine is just when I lint eslint takes it as an error.

7
  • Sounds like an outdated parser that doesn't understand template literal types. Commented Nov 3, 2022 at 18:03
  • 1
    @caTS Sure, but ESLint 8.21.0 came out in Aug 2022, and TypeScript template literal support has been around since 2020 per typescript-eslint/typescript-eslint#2583. @Woohaik Do you have an ESLint config file with a configuration that specifies @typescript-eslint? Can you post it here? Commented Nov 3, 2022 at 18:10
  • 1
    @JeffBowman I edited and added the .eslintrc.json Commented Nov 3, 2022 at 18:16
  • 1
    Stubbing in MSERVICES, this seems to work with or without your config in the typescript-eslint playground. Are you calling the right eslint? Do you need npx eslint? Commented Nov 3, 2022 at 18:25
  • 1
    @JeffBowman thank you for the playground, I see and double checked and the problem was the typescript version, Im using the aws cdk and apparently by default install typescript v3.9.7. Commented Nov 3, 2022 at 18:48

1 Answer 1

2

Resolved in the comments:

I see and double checked and the problem was the typescript version, Im using the aws cdk and apparently by default install typescript v3.9.7. —Woohaik

Template literal types were introduced in TypeScript 4.1, so ESLint was correctly flagging that this syntax was unexpected.

It was helpful to debug this through the use of the Typescript-ESLint Playground.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.