Skip to content

Commit

Permalink
fix(types): add types for process.sentry (#153)
Browse files Browse the repository at this point in the history
Extending a namespace must be done in a definition file that has no
top-level imports so that the file is treated as ambient module
rather than a normal module. For that reason, I couldn't just put new
code in `index.d.ts` but had to create separate file. Stuff from
`index.d.ts` moved to `extend.d.ts` to have a cleaner structure.
  • Loading branch information
rchl authored Feb 13, 2020
1 parent 8ffce3a commit 0ff5969
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
26 changes: 26 additions & 0 deletions types/extend.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as SentryTypes from '@sentry/minimal';

// add type to Vue context
declare module 'vue/types/vue' {
interface Vue {
readonly $sentry: typeof SentryTypes;
}
}

// App Context and NuxtAppOptions
declare module '@nuxt/types' {
interface Context {
readonly $sentry: typeof SentryTypes;
}

interface NuxtAppOptions {
readonly $sentry: typeof SentryTypes;
}
}

// add types for Vuex Store
declare module 'vuex/types' {
interface Store<S> {
readonly $sentry: typeof SentryTypes;
}
}
28 changes: 2 additions & 26 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
import * as SentryTypes from '@sentry/minimal';

// add type to Vue context
declare module 'vue/types/vue' {
interface Vue {
readonly $sentry: typeof SentryTypes;
}
}

// App Context and NuxtAppOptions
declare module '@nuxt/types' {
interface Context {
readonly $sentry: typeof SentryTypes;
}

interface NuxtAppOptions {
readonly $sentry: typeof SentryTypes;
}
}

// add types for Vuex Store
declare module 'vuex/types' {
interface Store<S> {
readonly $sentry: typeof SentryTypes;
}
}
import './extend';
import './node';
5 changes: 5 additions & 0 deletions types/node.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace NodeJS {
interface Process {
sentry: typeof import('@sentry/node');
}
}

0 comments on commit 0ff5969

Please sign in to comment.