RocketChat / RocketChat/Rocket.Chat
Message parser ASTNode types are incomplete and break type narrowing for valid parser output
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Description:
The message parser emits AST node types that are not represented in the ASTNode union defined in definitions.ts. As a result, helper guards such as isNodeOfType cannot correctly type-narrow valid parser output.
For example, nodes like TIMESTAMP, IMAGE, ORDERED_LIST, and others are produced by the parser at runtime, but are missing from the ASTNode union. This creates a mismatch between runtime behavior and compile-time typing, leading to incorrect or impossible type narrowing in TypeScript.
This weakens the AST contract, reduces developer confidence, and increases risk during future parser refactors or rewrites.
Affected files include:
packages/message-parser/src/definitions.tspackages/message-parser/src/guards.ts
Steps to reproduce:
- Use the message parser to parse input that produces nodes such as timestamps, images, or ordered lists.
- Attempt to narrow the parsed output using
isNodeOfTypeor related AST guards. - Observe that TypeScript cannot correctly narrow the node type, even though the node is valid at runtime.
Expected behavior:
All AST node types emitted by the message parser should be represented in the ASTNode union.
Type guards like isNodeOfType should correctly narrow TypeScript types for all valid parser output nodes.
This should provide strong compile-time safety and accurate AST contracts.
Actual behavior:
Valid AST node types emitted by the parser are missing from the ASTNode union.
Type guards fail to narrow types correctly, causing compile-time type errors or forcing unsafe casts.
This creates a discrepancy between runtime behavior and TypeScript typings.
Server Setup Information:
- Version of Rocket.Chat Server: N/A (parser/type definition issue)
- License Type: N/A
- Number of Users: N/A
- Operating System: N/A
- Deployment Method: N/A
- Number of Running Instances: N/A
- DB Replicaset Oplog: N/A
- NodeJS Version: N/A
- MongoDB Version: N/A
Client Setup Information
- Desktop App or Browser Version: N/A
- Operating System: N/A
Additional context
This issue directly affects rewrite safety and maintainability of the message parser. Ensuring that AST type definitions accurately reflect runtime output is especially important ahead of any parser refactor or performance-focused rewrite.
Relevant logs:
No runtime logs required. This issue is reproducible via code inspection and TypeScript type checking.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the parser's emitted node types with the ASTNode union in packages/message-parser/src/definitions.ts, then inspect the related guards in packages/message-parser/src/guards.ts. Use TypeScript type checking with inputs that produce TIMESTAMP, IMAGE, and ORDERED_LIST nodes. Done means every valid emitted node is represented and isNodeOfType narrows those nodes without unsafe casts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100