feat(types): add runtimeConfig types (nuxt/typescript#368)

Co-Authored-By: Kevin Marrec <kevin@marrec.io>
This commit is contained in:
Pooya Parsa 2020-06-18 18:07:08 +02:00
parent 99432d5d94
commit b6e8b74833
4 changed files with 19 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { IncomingMessage } from 'connect'
import Vue, { ComponentOptions } from 'vue'
import VueRouter, { Location, Route } from 'vue-router'
import { Store } from 'vuex'
import { NuxtRuntimeConfig } from '../config/runtime'
// augment typings of Vue.js
import './vue'
@ -13,6 +14,8 @@ import './vuex'
type NuxtState = Record<string, any>
export interface Context {
$config: NuxtRuntimeConfig
app: NuxtAppOptions
base: string
/**

View File

@ -2,10 +2,11 @@
* Extends interfaces in Vue.js
*/
import Vue, { ComponentOptions } from 'vue'
import Vue from 'vue'
import { MetaInfo } from 'vue-meta'
import { Route } from 'vue-router'
import { Context, Middleware, Transition, NuxtApp } from './index'
import { NuxtRuntimeConfig } from '../config/runtime'
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
@ -28,6 +29,7 @@ declare module 'vue/types/options' {
declare module 'vue/types/vue' {
interface Vue {
$config: NuxtRuntimeConfig
$nuxt: NuxtApp
$fetch(): void
$fetchState: {

View File

@ -13,6 +13,7 @@ import { NuxtOptionsModule } from './module'
import { NuxtOptionsPlugin } from './plugin'
import { NuxtOptionsRender } from './render'
import { NuxtOptionsRouter } from './router'
import { NuxtConfigurationRuntimeConfig } from './runtime'
import { NuxtOptionsServer } from './server'
import { NuxtOptionsServerMiddleware } from './server-middleware'
import { NuxtOptionsVueConfiguration } from './vue-configuration'
@ -50,6 +51,8 @@ export interface NuxtOptions extends Record<string, any> {
modules: NuxtOptionsModule[]
modulesDir: string[]
plugins: NuxtOptionsPlugin[]
privateRuntimeConfig?: NuxtConfigurationRuntimeConfig
publicRuntimeConfig?: NuxtConfigurationRuntimeConfig
render: NuxtOptionsRender
rootDir: string
router: NuxtOptionsRouter

10
packages/types/config/runtime.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
/**
* NuxtConfigurationRuntimeConfig
* NuxtRuntimeConfig interface can be extended by users to enable intellisense on $config
*/
export interface NuxtRuntimeConfig {
[key: string]: any
}
export type NuxtConfigurationRuntimeConfig = NuxtRuntimeConfig | ((env: typeof process.env) => NuxtRuntimeConfig)