TypeScript Compiler API

ts.displayPartsToString()

Concatenates structured compiler display parts into plain text, returning an empty string for undefined. Useful for documentation, hover text and signature displays; this loses part kind metadata and does not sanitize text for HTML rendering. Baseline: TypeScript 5.8.3 and Node.js. The example is a local tooling script in a disposable directory; it writes temporary project files, not a ByteMind CodeRunner exercise.

Formal Syntax & Structure

typescript syntaxtypescript
ts.displayPartsToString(displayParts: ts.SymbolDisplayPart[] | undefined): string

Parameters & Attributes

NameTypeDescription
displayPartsts.SymbolDisplayPart[] | undefinedStructured display parts or undefined.

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 fs = require("node:fs");const path = require("node:path");const parts=[{text:"const",kind:"keyword"},{text:" ",kind:"space"},{text:"count",kind:"localName"}];assert.equal(ts.displayPartsToString(parts),"const count"); assert.equal(ts.displayPartsToString(undefined),"");console.log(ts.displayPartsToString(parts));
// Run: node example.cjs// Expected stdout: const count
TypeScript Reference