TypeScript Compiler API
ts.isIdentifier()
Tests the AST syntax kind and narrows a Node to Identifier in TypeScript. Identifier text is not a resolved symbol; equal spellings may belong to unrelated declarations. Use a TypeChecker for semantic identity. Baseline: TypeScript 5.8.3; run locally with Node.js, not as a ByteMind CodeRunner exercise.
Formal Syntax & Structure
typescript syntaxtypescript
ts.isIdentifier(node: ts.Node): node is ts.IdentifierParameters & Attributes
| Name | Type | Description |
|---|---|---|
| node | ts.Node | AST node to inspect. |
Working 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 parse(text) { return ts.createSourceFile("input.ts", text, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS);}const f=parse("const x = 1;"); const d=f.statements[0].declarationList.declarations[0];assert(ts.isIdentifier(d.name)); assert.equal(d.name.text,"x"); assert(!ts.isIdentifier(d.initializer));console.log("x is identifier; 1 is not");
// Run: node example.cjs// Expected stdout: x is identifier; 1 is not