Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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