From 5f1aeb9b2298a06aa4bd3e7e2db4b3700b6e84d8 Mon Sep 17 00:00:00 2001 From: Dustin Stewart Date: Wed, 30 Aug 2023 14:59:53 -0600 Subject: [PATCH] Replaced 'as' with a type guard. --- src/module.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/module.ts b/src/module.ts index 317d9ef..af71143 100644 --- a/src/module.ts +++ b/src/module.ts @@ -26,13 +26,17 @@ export default defineNuxtModule>({ nuxt.hook('vite:extendConfig', (config, { isClient }) => { const mode = isClient ? 'client' : 'server' + const sourcemapValue = nuxt.options.sourcemap[mode] + if (typeof sourcemapValue !== 'boolean') { + throw new TypeError(`Expected a boolean for sourcemap[${mode}], but received ${typeof sourcemapValue}.`) + } config.plugins = config.plugins || [] config.plugins.push( transformPlugin.vite({ include: options.include, exclude: options.exclude, - sourcemap: nuxt.options.sourcemap[mode] as boolean, + sourcemap: sourcemapValue, transformStyles: name => resolveStyles(options, name) }) ) @@ -41,13 +45,17 @@ export default defineNuxtModule>({ nuxt.hook('webpack:config', (configs) => { configs.forEach((config) => { const mode = config.name === 'client' ? 'client' : 'server' + const sourcemapValue = nuxt.options.sourcemap[mode] + if (typeof sourcemapValue !== 'boolean') { + throw new TypeError(`Expected a boolean for sourcemap[${mode}], but received ${typeof sourcemapValue}.`) + } config.plugins = config.plugins || [] config.plugins.push( transformPlugin.webpack({ include: options.include, exclude: options.exclude, - sourcemap: nuxt.options.sourcemap[mode] as boolean, + sourcemap: sourcemapValue, transformStyles: name => resolveStyles(options, name) }) )