Skip to content

Using getSymbolAtLocation on side effect import's module specifier produces TS2307 diagnostic #35973

@ark120202

Description

@ark120202

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions