From 0ff59695103c613d21956add54c15b12144de526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Thu, 13 Feb 2020 09:15:14 +0100 Subject: [PATCH] fix(types): add types for process.sentry (#153) 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. --- types/extend.d.ts | 26 ++++++++++++++++++++++++++ types/index.d.ts | 28 ++-------------------------- types/node.d.ts | 5 +++++ 3 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 types/extend.d.ts create mode 100644 types/node.d.ts diff --git a/types/extend.d.ts b/types/extend.d.ts new file mode 100644 index 00000000..282d27b0 --- /dev/null +++ b/types/extend.d.ts @@ -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 { + readonly $sentry: typeof SentryTypes; + } +} diff --git a/types/index.d.ts b/types/index.d.ts index 282d27b0..1f5fb248 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 { - readonly $sentry: typeof SentryTypes; - } -} +import './extend'; +import './node'; diff --git a/types/node.d.ts b/types/node.d.ts new file mode 100644 index 00000000..cdef9e8f --- /dev/null +++ b/types/node.d.ts @@ -0,0 +1,5 @@ +declare namespace NodeJS { + interface Process { + sentry: typeof import('@sentry/node'); + } +}