Skip to content

Fix SourceNode.children type to include strings - #533

Closed
Hanabi9248 wants to merge 1 commit into
mozilla:masterfrom
Hanabi9248:codex/source-node-children-types
Closed

Hanabi9248 wants to merge 1 commit into
mozilla:masterfrom
Hanabi9248:codex/source-node-children-types

Conversation

@Hanabi9248

Copy link
Copy Markdown

Fixes #482.

SourceNode.add() and prepend() store both strings and SourceNode instances in children, but the declaration only allows SourceNode[]. This rejects valid string children and lets callers access node methods without narrowing.

Change the element type to SourceNode | string, matching the implementation and the existing chunk parameter types.

Verified with TypeScript 5.9.3 (--strict --noEmit --lib es2015): mixed children and string narrowing fail before this change and pass afterward; node-only access without narrowing and numeric children are rejected. The 18 existing SourceNode runtime tests also pass.

@Hanabi9248 Hanabi9248 closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SourceNode.children type incorrect

1 participant