feat: define nitro `#storage` and `#assets` types (#1377)

This commit is contained in:
Daniel Roe 2021-10-22 23:25:49 +01:00 committed by GitHub
parent 06e9c7ebc1
commit 281790e036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -129,6 +129,11 @@ export function setupNitroBridge () {
// Add typed route responses
nuxt.hook('prepare:types', (opts) => {
opts.references.push({ path: resolve(nuxt.options.buildDir, 'nitro.d.ts') })
for (const stub of ['#storage', '#assets']) {
// The `@nuxt/nitro` types will be overwritten by packages/nitro/types/shims.d.ts
opts.tsConfig.compilerOptions.paths[stub] = ['@nuxt/nitro']
}
})
// nuxt build/dev

View File

@ -5,7 +5,7 @@ declare module '#storage' {
declare module '#assets' {
export interface AssetMeta { type?: string, etag?: string, mtime?: string }
export function readAsset<T=any>(id: string): Promise<T>
export function statAsset(id: string): Promise<AssetMeta>
export function readAsset<T = any> (id: string): Promise<T>
export function statAsset (id: string): Promise<AssetMeta>
export function getKeys() : Promise<string[]>
}

View File

@ -27,7 +27,10 @@ export const writeTypes = async (nuxt: Nuxt) => {
const aliases = {
...nuxt.options.alias,
'#build': nuxt.options.buildDir
'#build': nuxt.options.buildDir,
// The `@nuxt/nitro` types will be overwritten by packages/nitro/types/shims.d.ts
'#storage': '@nuxt/nitro',
'#assets': '@nuxt/nitro'
}
for (const alias in aliases) {