11import * as crypto from 'crypto' ;
22import * as path from 'path' ;
33import type * as typescript from 'typescript' ;
4+ import type * as webpack from 'webpack' ;
45
56import * as constants from './constants' ;
67import {
@@ -17,8 +18,6 @@ import {
1718 LoaderOptionsCache ,
1819 LogLevel ,
1920 TSInstance ,
20- WebpackLoaderCallback ,
21- WebpackLoaderContext ,
2221} from './interfaces' ;
2322import {
2423 appendSuffixesIfMatch ,
@@ -32,9 +31,9 @@ const loaderOptionsCache: LoaderOptionsCache = {};
3231/**
3332 * The entry point for ts-loader
3433 */
35- function loader ( this : WebpackLoaderContext , contents : string ) {
34+ function loader ( this : webpack . LoaderContext < LoaderOptions > , contents : string ) {
3635 this . cacheable && this . cacheable ( ) ;
37- const callback = this . async ( ) as WebpackLoaderCallback ;
36+ const callback = this . async ( ) ;
3837 const options = getLoaderOptions ( this ) ;
3938 const instanceOrError = getTypeScriptInstance ( options , this ) ;
4039
@@ -48,9 +47,9 @@ function loader(this: WebpackLoaderContext, contents: string) {
4847}
4948
5049function successLoader (
51- loaderContext : WebpackLoaderContext ,
50+ loaderContext : webpack . LoaderContext < LoaderOptions > ,
5251 contents : string ,
53- callback : WebpackLoaderCallback ,
52+ callback : ReturnType < webpack . LoaderContext < LoaderOptions > [ 'async' ] > ,
5453 instance : TSInstance
5554) {
5655 initializeInstance ( loaderContext , instance ) ;
@@ -96,9 +95,9 @@ function makeSourceMapAndFinish(
9695 outputText : string | undefined ,
9796 filePath : string ,
9897 contents : string ,
99- loaderContext : WebpackLoaderContext ,
98+ loaderContext : webpack . LoaderContext < LoaderOptions > ,
10099 fileVersion : number ,
101- callback : WebpackLoaderCallback ,
100+ callback : ReturnType < webpack . LoaderContext < LoaderOptions > [ 'async' ] > ,
102101 instance : TSInstance
103102) {
104103 if ( outputText === null || outputText === undefined ) {
@@ -135,19 +134,19 @@ function makeSourceMapAndFinish(
135134}
136135
137136function setModuleMeta (
138- loaderContext : WebpackLoaderContext ,
137+ loaderContext : webpack . LoaderContext < LoaderOptions > ,
139138 instance : TSInstance ,
140139 fileVersion : number
141140) {
142141 // _module.meta is not available inside happypack
143142 if (
144143 ! instance . loaderOptions . happyPackMode &&
145- loaderContext . _module . buildMeta !== undefined
144+ loaderContext . _module ! . buildMeta !== undefined
146145 ) {
147146 // Make sure webpack is aware that even though the emitted JavaScript may be the same as
148147 // a previously cached version the TypeScript may be different and therefore should be
149148 // treated as new
150- loaderContext . _module . buildMeta . tsLoaderFileVersion = fileVersion ;
149+ loaderContext . _module ! . buildMeta . tsLoaderFileVersion = fileVersion ;
151150 }
152151}
153152
@@ -174,8 +173,8 @@ function getOptionsHash(loaderOptions: LoaderOptions) {
174173 * either retrieves loader options from the cache
175174 * or creates them, adds them to the cache and returns
176175 */
177- function getLoaderOptions ( loaderContext : WebpackLoaderContext ) {
178- const loaderOptions = loaderContext . getOptions ( undefined ) ;
176+ function getLoaderOptions ( loaderContext : webpack . LoaderContext < LoaderOptions > ) {
177+ const loaderOptions = loaderContext . getOptions ( ) ;
179178
180179 // If no instance name is given in the options, use the hash of the loader options
181180 // In this way, if different options are given the instances will be different
@@ -389,7 +388,7 @@ function getEmit(
389388 rawFilePath : string ,
390389 filePath : string ,
391390 instance : TSInstance ,
392- loaderContext : WebpackLoaderContext
391+ loaderContext : webpack . LoaderContext < LoaderOptions >
393392) {
394393 const outputFiles = getEmitOutput ( instance , filePath ) ;
395394 loaderContext . clearDependencies ( ) ;
@@ -435,7 +434,7 @@ function getEmit(
435434
436435 addDependenciesFromSolutionBuilder ( instance , filePath , addDependency ) ;
437436
438- loaderContext . _module . buildMeta . tsLoaderDefinitionFileVersions = dependencies . map (
437+ loaderContext . _module ! . buildMeta . tsLoaderDefinitionFileVersions = dependencies . map (
439438 defFilePath =>
440439 path . relative ( loaderContext . rootContext , defFilePath ) +
441440 '@' +
@@ -586,7 +585,7 @@ function getTranspilationEmit(
586585 fileName : string ,
587586 contents : string ,
588587 instance : TSInstance ,
589- loaderContext : WebpackLoaderContext
588+ loaderContext : webpack . LoaderContext < LoaderOptions >
590589) {
591590 if ( isReferencedFile ( instance , fileName ) ) {
592591 const outputFiles = instance . solutionBuilderHost ! . getOutputFilesFromReferencedProjectInput (
@@ -625,7 +624,7 @@ function getTranspilationEmit(
625624 loaderContext . context
626625 ) ;
627626
628- errors . forEach ( error => module . addError ( error ) ) ;
627+ errors . forEach ( error => module ! . addError ( error ) ) ;
629628 }
630629
631630 return { outputText, sourceMapText } ;
@@ -636,7 +635,7 @@ function makeSourceMap(
636635 outputText : string ,
637636 filePath : string ,
638637 contents : string ,
639- loaderContext : WebpackLoaderContext
638+ loaderContext : webpack . LoaderContext < LoaderOptions >
640639) {
641640 if ( sourceMapText === undefined ) {
642641 return { output : outputText , sourceMap : undefined } ;
0 commit comments