Correct way of extending tsconfig lib in a vue project #14220
-
|
My question is kind of related to this topic: https://github.com/orgs/vuejs/discussions/13583 // Target ES2020 to align with Vite.
// <https://vite.dev/config/build-options.html#build-target>
// Support for newer versions of language built-ins are
// left for the users to include, because that would require:
// - either the project doesn't need to support older versions of browsers;
// - or the project has properly included the necessary polyfills.So Baseline availabe features like {
"compilerOptions": {
"lib": [
"ESNext", // Or whatever I need
"DOM", // I have to set all the other values, because I override lib here
"DOM.Iterable"
],
}
}To me this feels kind of wrong, because as soon as the So is this the correct way to deal with making new features available? Or is there some smarter way that I don't know? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Yeah unfortunately thats how TypeScript works - the Your approach is correct but theres a cleaner way. Instead of manually listing all libs, you can check what the base config includes and just add what you need: {
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"lib": ["ES2020", "DOM", "DOM.Iterable", "ESNext.Object"]
}
}For {
"compilerOptions": {
"lib": ["ES2020", "DOM", "DOM.Iterable", "ESNext"]
}
}Or if you only want {
"compilerOptions": {
"lib": ["ES2020", "DOM", "DOM.Iterable", "ES2024"]
}
}The thing is - when base tsconfig updates, you would need to update yours too. Theres no automatic merge unfortunately. One workaround some people use is to not extend for compilerOptions and just copy what they need. But honestly for most projects, setting |
Beta Was this translation helpful? Give feedback.
Yeah unfortunately thats how TypeScript works - the
libarray doesnt merge, it completely overrides.Your approach is correct but theres a cleaner way. Instead of manually listing all libs, you can check what the base config includes and just add what you need:
{ "extends": "@vue/tsconfig/tsconfig.dom.json", "compilerOptions": { "lib": ["ES2020", "DOM", "DOM.Iterable", "ESNext.Object"] } }For
Object.groupByspecifically, you needESNextorES2024in your lib:{ "compilerOptions": { "lib": ["ES2020", "DOM", "DOM.Iterable", "ESNext"] } }Or if you only want
Object.groupBywithout all ESNext stuff:{ "compilerOptions": { "lib": ["ES2020", "DOM", "DOM.Iterable", "ES2024"