Skip to content

Instantly share code, notes, and snippets.

@stepbeekio
Created August 14, 2018 11:12
Show Gist options
  • Save stepbeekio/1d5392b13503dca248556f0457e83ffd to your computer and use it in GitHub Desktop.
Save stepbeekio/1d5392b13503dca248556f0457e83ffd to your computer and use it in GitHub Desktop.
Typescript working with asyncData & fetch for Nuxt.js
import Vue from 'vue'
import { Store } from 'vuex'
// ComponentOptions is declared in types/options.d.ts
declare module 'vue/types/options' {
interface NuxtContext<V extends Vue> {
app: V,
isClient: boolean,
isServer: boolean,
isStatic: boolean,
isDev: boolean,
store: Store<any>, // Consider vuex-typex in future
env: object,
params: object,
query: object
}
interface ComponentOptions<V extends Vue> {
asyncData?(context: NuxtContext<V>): Promise<object> | object
fetch?(context: NuxtContext<V>): Promise<object> | object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment