types: add global and shims for app and nitro (#102)

This commit is contained in:
pooya parsa 2021-04-20 13:57:18 +02:00 committed by GitHub
parent 5646770cd1
commit a63347b0ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 59 additions and 27 deletions

View File

@ -5,9 +5,10 @@
"license": "MIT",
"main": "./dist/app/index.js",
"module": "./dist/app/index.js",
"types": "./dist/index.d.ts",
"types": "./types/index.d.ts",
"files": [
"dist",
"types",
"meta.js"
],
"scripts": {

View File

@ -1,3 +1,2 @@
export * from './nuxt'
export * from './shim'
export * from './composables'

3
packages/app/types/index.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
import './shims'
export * from '../dist/app'

View File

@ -1,24 +1,36 @@
import type { Nuxt } from './nuxt'
declare module 'vue' {
interface App {
$nuxt: Nuxt
}
}
declare global {
interface Window {
__NUXT__?: Record<string, any>
}
import type { $Fetch } from 'ohmyfetch'
// eslint-disable-next-line no-var
var $fetch: $Fetch
namespace NodeJS {
interface Global {
$fetch: $Fetch
}
interface Process {
browser: boolean
client: boolean
mode: 'spa' | 'universal'
modern: boolean
server: boolean
static: boolean
}
}
interface Window {
__NUXT__?: Record<string, any>
}
}
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}
declare module 'vue' {
import type { Nuxt } from '../dist/app'
interface App {
$nuxt: Nuxt
}
}

View File

@ -3,8 +3,10 @@
"version": "0.5.2",
"license": "MIT",
"main": "dist/index.js",
"types": "./types/index.d.ts",
"files": [
"dist",
"types",
"compat.js"
],
"scripts": {

View File

@ -2,5 +2,4 @@ export * from './build'
export * from './context'
export * from './server/middleware'
export * from './server/dev'
export * from './types'
export { wpfs } from './utils/wpfs'

View File

@ -1,11 +0,0 @@
import type { $Fetch } from 'ohmyfetch'
declare global {
const $fetch: $Fetch
namespace NodeJS {
interface Global {
$fetch: $Fetch
}
}
}

3
packages/nitro/types/index.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
import './shims'
export * from '../dist/index'

22
packages/nitro/types/shims.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
declare global {
import type { $Fetch } from 'ohmyfetch'
// eslint-disable-next-line no-var
var $fetch: $Fetch
namespace NodeJS {
interface Global {
$fetch: $Fetch
}
}
}
declare module '#storage' {
import type { Storage } from 'unstorage'
export const storage: 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 getAsset<T=any>(id: string): { read: () => Promise<T>, meta: AssetMeta }
}

View File

@ -10,7 +10,9 @@
"resolveJsonModule": true,
"types": [
"node",
"jest"
"jest",
"@nuxt/app",
"@nuxt/nitro",
]
},
"exclude": ["./packages/*/dist/*"]