I think it is better to use typeRoots than types.
That's because if you use types, you have to add it to types explicitly when you add @types/xxx as your dependency.
Specifically, you should write the following in defaultTsJsonConfig:
export const defaultTsJsonConfig = {
compilerOptions: {
target: 'esnext',
module: 'esnext',
moduleResolution: 'node',
lib: [
'esnext',
'esnext.asynciterable',
'dom'
],
esModuleInterop: true,
experimentalDecorators: true,
allowJs: true,
sourceMap: true,
strict: true,
noImplicitAny: false,
noEmit: true,
baseUrl: '.',
paths: {
'~/*': [
'./*'
],
'@/*': [
'./*'
]
},
typeRoots: [
'./node_modules/@types',
'./node_modules/@nuxt/vue-app/types'
]
}
}
@iwata Thanks for your proposal, I will closely check if it better fits for the next major TS change (which should switch back to the extends way instead of overriding tsconfig.json when Nuxt is starting)
@iwata The issue with typeRoots is that it needs relative path, and people might have their node_modules not in current folder where is running nuxt.
See
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types
I suggest keeping types for now.
I'm working on changes which will only create tsconfig.json with these values only if the file is missing. So then people can change and use typeRoots (they already can do) if they really need it.
@kevinmarrec
Thanks your prompt reply.
I'm working on changes which will only create tsconfig.json with these values only if the file is missing.
That's great.
It's related by this second question.
https://cmty.app/nuxt/nuxt.js/issues/c8891
@iwata Everything you mentioned won't be longer issues with https://github.com/nuxt/nuxt.js/pull/5367
And yes, @nuxt/typescript should be installed as dependency and not devDependency to prevent error in production to be able to use nuxt start. See docs PR linked to the link above, I changed it so it tells user to install it as dependency.
It will also be in released notes when it will be released.
Most helpful comment
@iwata The issue with
typeRootsis that it needs relative path, and people might have theirnode_modulesnot in current folder where is running nuxt.See
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types
I suggest keeping
typesfor now.I'm working on changes which will only create
tsconfig.jsonwith these values only if the file is missing. So then people can change and usetypeRoots(they already can do) if they really need it.