Closed
Description
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
Code
const ts = require('typescript');
const files = {
'main.ts': 'import "./module";',
'module.d.ts': 'declare const foo: any;'
};
const host = ts.createCompilerHost({})
const originalReadFile = host.readFile;
host.readFile = (fileName) => files[fileName] || originalReadFile(fileName);
const program = ts.createProgram({ host, rootNames: ['main.ts'], options: { types: [] } });
const typeChecker = program.getDiagnosticsProducingTypeChecker();
const sourceFile = program.getSourceFile('main.ts');
typeChecker.getSymbolAtLocation(sourceFile.statements[0].moduleSpecifier);
console.log(program.getSemanticDiagnostics());
Expected behavior:
getSemanticDiagnostics
to return an empty array
Actual behavior:
TS2307: Cannot find module './module'.
Removing getSemanticDiagnostics
or using getTypeAtLocation
instead does not produce a diagnostic.
Similarly to #34913, it's observable only with diagnostics producing type checker.
Playground Link:
Related Issues: #34913