Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@ark120202

Description

@ark120202
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.