mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
fix(nitro): type inference for api routes returning promise (#1483)
This commit is contained in:
parent
3bc984d0c0
commit
245aa6b68f
@ -70,12 +70,13 @@ async function writeTypes (nitroContext: NitroContext) {
|
||||
if (typeof mw.handle !== 'string') { continue }
|
||||
const relativePath = relative(nitroContext._nuxt.buildDir, mw.handle).replace(/\.[a-z]+$/, '')
|
||||
routeTypes[mw.route] = routeTypes[mw.route] || []
|
||||
routeTypes[mw.route].push(`ReturnType<typeof import('${relativePath}').default>`)
|
||||
routeTypes[mw.route].push(`Awaited<ReturnType<typeof import('${relativePath}').default>>`)
|
||||
}
|
||||
|
||||
const lines = [
|
||||
'// Generated by nitro',
|
||||
'declare module \'@nuxt/nitro\' {',
|
||||
' type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T',
|
||||
' interface InternalApi {',
|
||||
...Object.entries(routeTypes).map(([path, types]) => ` '${path}': ${types.join(' | ')}`),
|
||||
' }',
|
||||
|
Loading…
Reference in New Issue
Block a user