Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A multi-line comment in TypeScript is a lexical construct that instructs the compiler to ignore a sequence of characters spanning one or more lines. During lexical analysis, the TypeScript scanner tokenizes these blocks as SyntaxKind.MultiLineCommentTrivia. While comments are classified as trivia rather than standard Abstract Syntax Tree (AST) nodes, the compiler tracks their positional ranges and associates them with adjacent AST nodes. Syntax The construct is delimited by a starting /* sequence and a terminating */ sequence.
/*
  Line one of the comment block.
  Line two of the comment block.
*/
let x: number = 10;
Technical Characteristics
  • Inline Masking: Although termed “multi-line,” the /* */ delimiters can be utilized inline to omit specific tokens within a single statement without breaking the line.
const price: number = 100;
const surcharge: number = 5;
const total: number = price + /* tax */ surcharge;
  • No Nesting Support: TypeScript does not support nested multi-line comments. The scanner terminates the comment block at the first instance of */. Any subsequent text or closing delimiters will be parsed as standard code, resulting in a syntax error.
/*
  Outer comment starts
  /* 
    Inner comment starts (Scanner ignores this as a new delimiter)
  */ // <- This terminates the entire comment block
  This text will cause a compiler error. 
*/
  • Compilation Behavior and Node Elision: Because comments are treated as trivia attached to specific AST nodes, their presence in the emitted JavaScript depends on the node they are attached to. If a multi-line comment is attached to a TypeScript-only node that is elided during compilation (such as a type alias or interface), the comment is also stripped from the emitted JavaScript, regardless of the removeComments compiler setting. For comments attached to standard JavaScript nodes, they are preserved by default unless the removeComments option in tsconfig.json is explicitly set to true.
  • Pinned Comments: A multi-line comment starting with an exclamation mark /*! is classified as a pinned comment. This compiler feature ensures that comments containing critical metadata are intentionally preserved in the emitted JavaScript, even when the removeComments option is set to true. Note that pinned comments will still be stripped if attached to an elided TypeScript-only node.
/*!
 * Copyright (c) 2024. All rights reserved.
 * This comment is preserved even if removeComments is true.
 */
const appVersion: string = "1.0.0";
  • JSDoc Parsing: If a multi-line comment begins with a double asterisk /**, it is tokenized as standard multi-line trivia but is specifically recognized as a JSDoc comment. The TypeScript language service actively parses these specific blocks to extract type information and generate editor tooling (IntelliSense).
/**
 * This is parsed by the TypeScript Language Service.
 */
const initialize = (): void => {};
Master TypeScript with Deep Grasping Methodology!Learn More