Skip to content

Commit f368c40

Browse files
committed
convert LoaderThis to generic type
1 parent 8a9c494 commit f368c40

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/nextjs/src/config/loaders/prefixLoader.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33

4+
import { LoaderThis } from './types';
5+
46
type LoaderOptions = {
57
distDir: string;
68
};
7-
// TODO Use real webpack types
8-
type LoaderThis = {
9-
// Webpack 4
10-
query?: LoaderOptions;
11-
// Webpack 5
12-
getOptions?: () => LoaderOptions;
13-
addDependency: (filepath: string) => void;
14-
};
159

1610
/**
1711
* Inject templated code into the beginning of a module.
1812
*/
19-
function prefixLoader(this: LoaderThis, userCode: string): string {
13+
function prefixLoader(this: LoaderThis<LoaderOptions>, userCode: string): string {
2014
// We know one or the other will be defined, depending on the version of webpack being used
2115
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2216
const { distDir } = this.getOptions ? this.getOptions() : this.query!;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// TODO Use real webpack types
2+
export type LoaderThis<Options> = {
3+
// Loader options in Webpack 4
4+
query?: Options;
5+
// Loader options in Webpack 5
6+
getOptions?: () => Options;
7+
8+
// Function to add outside file used by loader to `watch` process
9+
addDependency: (filepath: string) => void;
10+
};

0 commit comments

Comments
 (0)