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 getTypeAtLocation on a const type reference creates a TS2304 diagnostic #34913

Copy link
Copy link
@ark120202

Description

@ark120202
Issue body actions

TypeScript Version: 3.8.0-dev.20191102

Search Terms:

Code

const ts = require('typescript');

const content = '0 as const';

const host = ts.createCompilerHost({})
const originalReadFile = host.readFile;
host.readFile = (fileName) => fileName === 'main.ts' ? content : originalReadFile(fileName);

const program = ts.createProgram({ host, rootNames: ['main.ts'], options: { types: [] } });
const typeChecker = program.getDiagnosticsProducingTypeChecker();
const sourceFile = program.getSourceFile('main.ts');

typeChecker.getTypeAtLocation(sourceFile.statements[0].expression.type)

console.log(program.getSemanticDiagnostics());

Expected behavior:

getSemanticDiagnostics to return an empty array

Actual behavior:

TS2304: Cannot find name 'const'.

Because of caching, it has noticeable effects only when getSemanticDiagnostics is called after getTypeAtLocation.

It happens only when internal getDiagnosticsProducingTypeChecker method is used, but I think it still might be undesirable and would be an issue if #28584 would be merged.

Playground Link:

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    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.