TypeScript Compiler API

ts.SyntaxKind

An enum that labels syntax nodes and tokens. Compare a node kind with a named member or use a public type guard such as isFunctionDeclaration. Numeric values and reverse-mapping aliases are not stable identifiers across releases. This enum describes syntax, not inferred semantic types. Baseline: the Node.js API of TypeScript 5.8.3. The examples are CommonJS tooling scripts, not browser or CodeRunner snippets. TypeScript must be installed locally.

Formal Syntax & Structure

typescript syntaxtypescript
ts.SyntaxKind.FunctionDeclaration; node.kind: ts.SyntaxKind

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");const source = ts.createSourceFile("input.ts", "function twice(n: number) { return n * 2; }", ts.ScriptTarget.ES2022, true);const node = source.statements[0];assert.equal(node.kind, ts.SyntaxKind.FunctionDeclaration);assert(ts.isFunctionDeclaration(node));console.log(ts.SyntaxKind[node.kind]);
// Run: node example.cjs// Expected stdout: FunctionDeclaration
TypeScript Reference