@@ -479,6 +479,90 @@ namespace ts.projectSystem {
479479 session . clearMessages ( ) ;
480480 }
481481 } ) ;
482+
483+ it ( "Correct errors when resolution resolves to file that has same ambient module and is also module" , ( ) => {
484+ const projectRootPath = "/users/username/projects/myproject" ;
485+ const aFile : File = {
486+ path : `${ projectRootPath } /src/a.ts` ,
487+ content : `import * as myModule from "@custom/plugin";
488+ function foo() {
489+ // hello
490+ }`
491+ } ;
492+ const config : File = {
493+ path : `${ projectRootPath } /tsconfig.json` ,
494+ content : JSON . stringify ( { include : [ "src" ] } )
495+ } ;
496+ const plugin : File = {
497+ path : `${ projectRootPath } /node_modules/@custom/plugin/index.d.ts` ,
498+ content : `import './proposed';
499+ declare module '@custom/plugin' {
500+ export const version: string;
501+ }`
502+ } ;
503+ const pluginProposed : File = {
504+ path : `${ projectRootPath } /node_modules/@custom/plugin/proposed.d.ts` ,
505+ content : `declare module '@custom/plugin' {
506+ export const bar = 10;
507+ }`
508+ } ;
509+ const files = [ libFile , aFile , config , plugin , pluginProposed ] ;
510+ const host = createServerHost ( files ) ;
511+ const session = createSession ( host , { canUseEvents : true } ) ;
512+ const service = session . getProjectService ( ) ;
513+ openFilesForSession ( [ aFile ] , session ) ;
514+
515+ checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
516+ session . clearMessages ( ) ;
517+ checkErrors ( ) ;
518+
519+ session . executeCommandSeq < protocol . ChangeRequest > ( {
520+ command : protocol . CommandTypes . Change ,
521+ arguments : {
522+ file : aFile . path ,
523+ line : 3 ,
524+ offset : 8 ,
525+ endLine : 3 ,
526+ endOffset : 8 ,
527+ insertString : "o"
528+ }
529+ } ) ;
530+ checkErrors ( ) ;
531+
532+ function checkErrors ( ) {
533+ host . checkTimeoutQueueLength ( 0 ) ;
534+ const expectedSequenceId = session . getNextSeq ( ) ;
535+ session . executeCommandSeq < protocol . GeterrRequest > ( {
536+ command : server . CommandNames . Geterr ,
537+ arguments : {
538+ delay : 0 ,
539+ files : [ aFile . path ] ,
540+ }
541+ } ) ;
542+
543+ host . checkTimeoutQueueLengthAndRun ( 1 ) ;
544+
545+ checkErrorMessage ( session , "syntaxDiag" , { file : aFile . path , diagnostics : [ ] } , /*isMostRecent*/ true ) ;
546+ session . clearMessages ( ) ;
547+
548+ host . runQueuedImmediateCallbacks ( 1 ) ;
549+
550+ checkErrorMessage ( session , "semanticDiag" , { file : aFile . path , diagnostics : [ ] } ) ;
551+ session . clearMessages ( ) ;
552+
553+ host . runQueuedImmediateCallbacks ( 1 ) ;
554+
555+ checkErrorMessage ( session , "suggestionDiag" , {
556+ file : aFile . path ,
557+ diagnostics : [
558+ createDiagnostic ( { line : 1 , offset : 1 } , { line : 1 , offset : 44 } , Diagnostics . _0_is_declared_but_its_value_is_never_read , [ "myModule" ] , "suggestion" , /*reportsUnnecessary*/ true ) ,
559+ createDiagnostic ( { line : 2 , offset : 10 } , { line : 2 , offset : 13 } , Diagnostics . _0_is_declared_but_its_value_is_never_read , [ "foo" ] , "suggestion" , /*reportsUnnecessary*/ true )
560+ ] ,
561+ } ) ;
562+ checkCompleteEvent ( session , 2 , expectedSequenceId ) ;
563+ session . clearMessages ( ) ;
564+ }
565+ } ) ;
482566 } ) ;
483567
484568 describe ( "unittests:: tsserver:: Project Errors for Configure file diagnostics events" , ( ) => {
0 commit comments