mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
feat: typescript
options (#1940)
This commit is contained in:
parent
5f5eb39ae4
commit
b16cfea689
@ -29,3 +29,19 @@ This file contains the recommended basic TypeScript configuration for your proje
|
||||
::alert{icon=👉}
|
||||
Nitro also [auto-generates types](/concepts/server-engine#typed-api-routes) for API routes. Plus, Nuxt also generates types for globally available components and [auto-imports from your composables](/docs/directory-structure/composables), plus other core functionality.
|
||||
::
|
||||
|
||||
## Stricter Checks
|
||||
|
||||
TypeScript comes with certain checks to give you more safety and analysis of your program.
|
||||
|
||||
Once you’ve converted your codebase to TypeScript and felt familiar with, you can start enabling these checks for greater safety. ([read more](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html#getting-stricter-checks))
|
||||
|
||||
In order to enable strict type checking, you have to update `nuxt.confg`:
|
||||
|
||||
```js
|
||||
export default defineNuxtConfig({
|
||||
typescript: {
|
||||
strict: true
|
||||
}
|
||||
})
|
||||
```
|
||||
|
@ -9,6 +9,7 @@ import router from './router'
|
||||
import server from './server'
|
||||
import cli from './cli'
|
||||
import generate from './generate'
|
||||
import typescript from './typescript'
|
||||
|
||||
/*
|
||||
TODO for top level normalizations: (nuxt2)
|
||||
@ -38,5 +39,6 @@ export default {
|
||||
router,
|
||||
server,
|
||||
cli,
|
||||
generate
|
||||
generate,
|
||||
typescript
|
||||
}
|
||||
|
14
packages/kit/src/config/schema/typescript.ts
Normal file
14
packages/kit/src/config/schema/typescript.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export default {
|
||||
/**
|
||||
* TypeScript comes with certain checks to give you more safety and analysis of your program.
|
||||
* Once you’ve converted your codebase to TypeScript, you can start enabling these checks for greater safety.
|
||||
* [Read More](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html#getting-stricter-checks)
|
||||
*/
|
||||
strict: false,
|
||||
|
||||
/**
|
||||
* You can extend generated `.nuxt/tsconfig.json` using this option
|
||||
* @typedef {Awaited<ReturnType<typeof import('pkg-types')['readPackageJSON']>>}
|
||||
*/
|
||||
tsConfig: {}
|
||||
}
|
@ -1,19 +1,20 @@
|
||||
import { promises as fsp } from 'fs'
|
||||
import { join, relative, resolve } from 'pathe'
|
||||
import { Nuxt, TSReference } from '@nuxt/kit'
|
||||
import defu from 'defu'
|
||||
import type { TSConfig } from 'pkg-types'
|
||||
import { getModulePaths, getNearestPackage } from './cjs'
|
||||
|
||||
export const writeTypes = async (nuxt: Nuxt) => {
|
||||
const modulePaths = getModulePaths(nuxt.options.modulesDir)
|
||||
|
||||
const tsConfig: TSConfig = {
|
||||
const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, {
|
||||
compilerOptions: {
|
||||
target: 'ESNext',
|
||||
module: 'ESNext',
|
||||
moduleResolution: 'Node',
|
||||
skipLibCheck: true,
|
||||
strict: true,
|
||||
strict: nuxt.options.typescript.strict,
|
||||
allowJs: true,
|
||||
noEmit: true,
|
||||
resolveJsonModule: true,
|
||||
@ -27,7 +28,7 @@ export const writeTypes = async (nuxt: Nuxt) => {
|
||||
join(relative(nuxt.options.buildDir, nuxt.options.rootDir), '**/*'),
|
||||
...nuxt.options.srcDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.srcDir), '**/*')] : []
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
const aliases = {
|
||||
...nuxt.options.alias,
|
||||
|
Loading…
Reference in New Issue
Block a user