4

In a vue project, this is my tsconfig file:

{
   "extends": "@vue/tsconfig/tsconfig.web.json",
   "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "src/**/*.json"],
   "exclude": ["src/**/__tests__/*"],
      "compilerOptions": {
      "target": "es2021",
      "module": "ESNext",
      "lib":["ES2021", "DOM"], <-- If i remove this line, I get warnings in vue and .ts files
      "forceConsistentCasingInFileNames": false,
      "composite": true,
      "baseUrl": ".",
      "paths": {
         "@/*": ["./src/*"]
      },
      "allowJs": true,
      "outDir": "target",
      "noImplicitAny": false,
      "types": ["vite/client"],
      "strictNullChecks": false,
   }
 }

If my target is ES2021, I was expecting to be able to use ES2021 features without getting errors (ex: "resresr sdf".replaceAll(" ", "") is not a function). However it seems that I have to add "lib":["ES2021", "DOM"] to get rid of the error. Why do I have to add lib 2021?

Note that I am using Volar extension with takeover mode (https://vuejs.org/guide/typescript/overview.html#volar-takeover-mode) and have disabled Typescript vscode extension as per their recommendation. However before I did this, I was also getting the same warning.

I have tried restarting the Volar server in between making the changes and still no luck...

TS error showing

Thanks!

0

2 Answers 2

1

This is only a band-aid solution, but an explicit library target specified with the triple-slash directive should make things work on a per-file basis. So, until you figure out the config, I'd try adding the following line to the top of your file:

/// <reference lib="es2021" />
Sign up to request clarification or add additional context in comments.

Comments

0

"module" and "target" are compilerOptions properties but you've placed them outside of compilerOptions, it should be:

"compilerOptions": {
    "target": "ES2021",
    "module": "ESNext",
    ...
}

1 Comment

Thank you for the reply :). Sorry i actually moved that out as a failed experiment. Even when it lives inside, it still doesnt work without lib.

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.