From 4a856368ece10e15654c8bcf2b839ba844d33f78 Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Fri, 9 Feb 2018 13:11:52 -0500 Subject: [PATCH] Fix Loader type in webpack The sourcemap parameter passed to loaders, and that loaders pass to the callback, is a `RawSourceMap`, not a `string | Buffer`. --- types/webpack/index.d.ts | 6 ++++-- types/webpack/package.json | 6 ++++++ types/webpack/webpack-tests.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 types/webpack/package.json diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index f8aa375210..e8b59f2994 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -9,12 +9,14 @@ // Ahmed T. Ali // Alan Agius // Spencer Elliott +// Jason Cheatham // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// import Tapable = require('tapable'); import * as UglifyJS from 'uglify-js'; +import { RawSourceMap } from 'source-map'; export = webpack; @@ -1020,7 +1022,7 @@ declare namespace webpack { namespace loader { interface Loader extends Function { - (this: LoaderContext, source: string | Buffer, sourceMap: string | Buffer): string | Buffer | void | undefined; + (this: LoaderContext, source: string | Buffer, sourceMap?: RawSourceMap): string | Buffer | void | undefined; /** * The order of chained loaders are always called from right to left. @@ -1040,7 +1042,7 @@ declare namespace webpack { raw?: boolean; } - type loaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: string | Buffer) => void; + type loaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: RawSourceMap) => void; interface LoaderContext { /** diff --git a/types/webpack/package.json b/types/webpack/package.json new file mode 100644 index 0000000000..96c1491edd --- /dev/null +++ b/types/webpack/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.7.0" + } +} diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index d74960e4db..6bf8fb443b 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -637,7 +637,7 @@ configuration = { performance, }; -function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap: string | Buffer): void { +function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap?: object): void { this.cacheable(); this.async();