@@ -393,8 +393,8 @@ namespace ts {
393393 return resolutions ;
394394 }
395395
396- interface DiagnosticCache {
397- perFile ?: Map < DiagnosticWithLocation [ ] > ;
396+ interface DiagnosticCache < T extends Diagnostic > {
397+ perFile ?: Map < T [ ] > ;
398398 allDiagnostics ?: Diagnostic [ ] ;
399399 }
400400
@@ -500,8 +500,8 @@ namespace ts {
500500 let classifiableNames : UnderscoreEscapedMap < true > ;
501501 let modifiedFilePaths : Path [ ] | undefined ;
502502
503- const cachedSemanticDiagnosticsForFile : DiagnosticCache = { } ;
504- const cachedDeclarationDiagnosticsForFile : DiagnosticCache = { } ;
503+ const cachedSemanticDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
504+ const cachedDeclarationDiagnosticsForFile : DiagnosticCache < DiagnosticWithLocation > = { } ;
505505
506506 let resolvedTypeReferenceDirectives = createMap < ResolvedTypeReferenceDirective > ( ) ;
507507 let fileProcessingDiagnostics = createDiagnosticCollection ( ) ;
@@ -1209,10 +1209,10 @@ namespace ts {
12091209 return filesByName . get ( path ) ;
12101210 }
12111211
1212- function getDiagnosticsHelper (
1212+ function getDiagnosticsHelper < T extends Diagnostic > (
12131213 sourceFile : SourceFile ,
1214- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => ReadonlyArray < DiagnosticWithLocation > ,
1215- cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1214+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => ReadonlyArray < T > ,
1215+ cancellationToken : CancellationToken ) : ReadonlyArray < T > {
12161216 if ( sourceFile ) {
12171217 return getDiagnostics ( sourceFile , cancellationToken ) ;
12181218 }
@@ -1228,7 +1228,7 @@ namespace ts {
12281228 return getDiagnosticsHelper ( sourceFile , getSyntacticDiagnosticsForFile , cancellationToken ) ;
12291229 }
12301230
1231- function getSemanticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1231+ function getSemanticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
12321232 return getDiagnosticsHelper ( sourceFile , getSemanticDiagnosticsForFile , cancellationToken ) ;
12331233 }
12341234
@@ -1278,11 +1278,11 @@ namespace ts {
12781278 }
12791279 }
12801280
1281- function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1281+ function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
12821282 return getAndCacheDiagnostics ( sourceFile , cancellationToken , cachedSemanticDiagnosticsForFile , getSemanticDiagnosticsForFileNoCache ) ;
12831283 }
12841284
1285- function getSemanticDiagnosticsForFileNoCache ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : DiagnosticWithLocation [ ] {
1285+ function getSemanticDiagnosticsForFileNoCache ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
12861286 return runWithCancellationToken ( ( ) => {
12871287 // If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
12881288 // If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
@@ -1299,16 +1299,15 @@ namespace ts {
12991299 // By default, only type-check .ts, .tsx, and 'External' files (external files are added by plugins)
13001300 const includeBindAndCheckDiagnostics = sourceFile . scriptKind === ScriptKind . TS || sourceFile . scriptKind === ScriptKind . TSX ||
13011301 sourceFile . scriptKind === ScriptKind . External || isCheckJs ;
1302- const bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile . bindDiagnostics : emptyArray ;
1303- // TODO: GH#18217
1304- const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker . getDiagnostics ( sourceFile , cancellationToken ) as ReadonlyArray < DiagnosticWithLocation > : emptyArray ;
1302+ const bindDiagnostics : ReadonlyArray < Diagnostic > = includeBindAndCheckDiagnostics ? sourceFile . bindDiagnostics : emptyArray ;
1303+ const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker . getDiagnostics ( sourceFile , cancellationToken ) : emptyArray ;
13051304 const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
13061305 const programDiagnosticsInFile = programDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
13071306 let diagnostics = bindDiagnostics . concat ( checkDiagnostics , fileProcessingDiagnosticsInFile , programDiagnosticsInFile ) ;
13081307 if ( isCheckJs ) {
13091308 diagnostics = concatenate ( diagnostics , sourceFile . jsDocDiagnostics ) ;
13101309 }
1311- return filter < DiagnosticWithLocation > ( diagnostics , shouldReportDiagnostic ) ;
1310+ return filter < Diagnostic > ( diagnostics , shouldReportDiagnostic ) ;
13121311 } ) ;
13131312 }
13141313
@@ -1531,36 +1530,25 @@ namespace ts {
15311530 return ts . getDeclarationDiagnostics ( getEmitHost ( noop ) , resolver , sourceFile ) ;
15321531 } ) ;
15331532 }
1534- function getAndCacheDiagnostics (
1535- sourceFile : SourceFile ,
1536- cancellationToken : CancellationToken ,
1537- cache : DiagnosticCache ,
1538- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ]
1539- ) : ReadonlyArray < DiagnosticWithLocation > ;
1540- function getAndCacheDiagnostics (
1541- sourceFile : SourceFile | undefined ,
1542- cancellationToken : CancellationToken ,
1543- cache : DiagnosticCache ,
1544- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ] ,
1545- ) : ReadonlyArray < Diagnostic > ;
1546- function getAndCacheDiagnostics (
1533+
1534+ function getAndCacheDiagnostics < T extends Diagnostic > (
15471535 sourceFile : SourceFile | undefined ,
15481536 cancellationToken : CancellationToken ,
1549- cache : DiagnosticCache ,
1550- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ] ,
1551- ) : ReadonlyArray < Diagnostic > {
1537+ cache : DiagnosticCache < T > ,
1538+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => T [ ] ,
1539+ ) : ReadonlyArray < T > {
15521540
15531541 const cachedResult = sourceFile
15541542 ? cache . perFile && cache . perFile . get ( sourceFile . path )
1555- : cache . allDiagnostics ;
1543+ : cache . allDiagnostics as T [ ]
15561544
15571545 if ( cachedResult ) {
15581546 return cachedResult ;
15591547 }
15601548 const result = getDiagnostics ( sourceFile , cancellationToken ) || emptyArray ;
15611549 if ( sourceFile ) {
15621550 if ( ! cache . perFile ) {
1563- cache . perFile = createMap < DiagnosticWithLocation [ ] > ( ) ;
1551+ cache . perFile = createMap < T [ ] > ( ) ;
15641552 }
15651553 cache . perFile . set ( sourceFile . path , result ) ;
15661554 }
0 commit comments