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 asDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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.
- Inline Masking: Although termed “multi-line,” the
/* */delimiters can be utilized inline to omit specific tokens within a single statement without breaking the line.
- 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.
- 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
typealias orinterface), the comment is also stripped from the emitted JavaScript, regardless of theremoveCommentscompiler setting. For comments attached to standard JavaScript nodes, they are preserved by default unless theremoveCommentsoption intsconfig.jsonis explicitly set totrue. - 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 theremoveCommentsoption is set totrue. Note that pinned comments will still be stripped if attached to an elided TypeScript-only node.
- 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).
Master TypeScript with Deep Grasping Methodology!Learn More





