TypeScript Compiler API
Scanner.getTokenValue()
Reads the scanner-maintained value for the current token where meaningful, for example decoded string content or normalized numeric spelling. Do not assume this is a useful value for punctuation or all token kinds. It is not a runtime evaluator. Baseline: TypeScript 5.8.3; run locally with Node.js, not as a ByteMind CodeRunner exercise.
Formal Syntax & Structure
typescript syntaxtypescript
scanner.getTokenValue(): stringWorking Example
Example Snippettypescript
// Use a new empty directory. Install: npm install --save-exact typescript@5.8.3// File: example.cjs (omit this label)const ts = require("typescript");const assert = require("node:assert/strict");function scanner(text, skipTrivia = true) { return ts.createScanner(ts.ScriptTarget.ES2022, skipTrivia, ts.LanguageVariant.Standard, text);}const s = scanner('"a\\n" 0x10');assert.equal(s.scan(),ts.SyntaxKind.StringLiteral); assert.equal(s.getTokenValue(),"a\n");assert.equal(s.scan(),ts.SyntaxKind.NumericLiteral); assert.equal(s.getTokenValue(),"16");console.log("decoded string; numeric value 16");
// Run: node example.cjs// Expected stdout: decoded string; numeric value 16