Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ark120202 opened this issue Jan 3, 2020 · 4 comments · Fixed by #36742
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript

Comments

@ark120202
Copy link

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

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jan 31, 2020
@RyanCavanaugh
Copy link
Member

module.d.ts is not a module file

@ark120202
Copy link
Author

Yes, but it's referenced in the context of a side-effect import, which generally isn't checked. Usually it's not an issue because TypeScript itself doesn't try to get it's symbol, and API consumers don't have an access to diagnostics producing type checker, but they would have it with #28584

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

@ark120202
Copy link
Author

@RyanCavanaugh could you please take another look on this issue? It's not supposed to be a question.

@weswigham weswigham added API Relates to the public API for TypeScript Bug A bug in TypeScript and removed Question An issue which isn't directly actionable in code labels Feb 11, 2020
@weswigham weswigham reopened this Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript
Projects
None yet
4 participants