From c3bb037cc61d00542a4359613ab8a8f2382ac6b1 Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Sun, 17 Sep 2017 13:30:38 +0300 Subject: [PATCH] webpack: improve loader context typings emitError() and emitWarning() both can accept an Error as well, for exposing caught Errors. See: https://github.com/webpack/webpack/blob/master/lib/NormalModule.js#L115 Added relevant type tests. --- types/webpack/index.d.ts | 4 ++-- types/webpack/webpack-tests.ts | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index cbf48eebce..27f2560d4b 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -1162,13 +1162,13 @@ declare namespace webpack { * Emit a warning. * @param message */ - emitWarning(message: string): void; + emitWarning(message: string | Error): void; /** * Emit a error. * @param message */ - emitError(message: string): void; + emitError(message: string | Error): void; /** * Execute some code fragment like a module. diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index 6d56a0c3c3..6b7a7e0cb1 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -611,7 +611,11 @@ function loader(this: webpack.loader.LoaderContext, source: string, sourcemap: s this.resolve('context', 'request', ( err: Error, result: string) => {}); - this.emitError('warning'); + this.emitWarning('warning message'); + this.emitWarning(new Error('warning message')); + + this.emitError('error message'); + this.emitError(new Error('error message')); this.callback(null, source); }