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:
TypeScript Version: 3.8.0-dev.20191102
Search Terms:
Code
Expected behavior:
getSemanticDiagnosticsto return an empty arrayActual behavior:
TS2304: Cannot find name 'const'.Because of caching, it has noticeable effects only when
getSemanticDiagnosticsis called aftergetTypeAtLocation.It happens only when internal
getDiagnosticsProducingTypeCheckermethod is used, but I think it still might be undesirable and would be an issue if #28584 would be merged.Playground Link:
Related Issues: