Skip to content

[lexical][*] Chore: stop using deprecated traversal type parameters in tests#8667

Merged
etrepum merged 2 commits into
facebook:mainfrom
etrepum:claude/cleanup-deprecated-code-t4z1j1
Jun 10, 2026
Merged

[lexical][*] Chore: stop using deprecated traversal type parameters in tests#8667
etrepum merged 2 commits into
facebook:mainfrom
etrepum:claude/cleanup-deprecated-code-t4z1j1

Conversation

@etrepum

@etrepum etrepum commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Description

Migrate the remaining call sites (all in tests) off the deprecated unsafe type parameters that #8661 added to the node traversal methods (getFirstChild(), getParent(), getChildAtIndex(), $getNodeByKey(), etc.). The deprecated overloads themselves are retained for backwards compatibility with consumers.

Add a $assertNodeType test helper that narrows a node via a type guard instead of an unchecked cast, and use it (alongside the existing $is* guards) in place of the deprecated type parameters and a few remaining unsafe as casts in the affected tests.

Follow-up to #8661

Test plan

Only unit test syntax is affected, behavior should be identical and no runtime code has changed.

…acebook#8661 follow-up)

Migrate the remaining call sites (all in tests) off the deprecated unsafe
type parameters that facebook#8661 added to the node traversal methods
(getFirstChild<T>(), getParent<T>(), getChildAtIndex<T>(), $getNodeByKey<T>(),
etc.). The deprecated overloads themselves are retained for backwards
compatibility with consumers.

Add a $assertNodeType test helper that narrows a node via a type guard
instead of an unchecked cast, and use it (alongside the existing $is*
guards) in place of the deprecated type parameters and a few remaining
unsafe `as` casts in the affected tests.
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 10, 2026 1:55pm
lexical-playground Ready Ready Preview, Comment Jun 10, 2026 1:55pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 10, 2026

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

Assessment: LGTM

This is a well-scoped refactor that replaces deprecated generic type parameters on traversal methods (e.g. getFirstChildOrThrow<T>(), getFirstChild<T>(), getChildAtIndex<T>()) with a new runtime $assertNodeType() utility that uses type guards for type-safe narrowing.

What I checked:

  1. The $assertNodeType utility (packages/lexical/src/__tests__/utils/index.tsx): Clean implementation — takes a node | null | undefined and a type guard, throws a clear error if the guard fails. Returns the narrowed type. This is strictly better than the previous as T / ! pattern because it provides a runtime assertion rather than silently producing undefined behavior on type mismatch.

  2. Consistency of the migration pattern across all 21 test files: Every change follows the same mechanical pattern — getFirstChildOrThrow<Foo>()$assertNodeType(getFirstChild(), $isFoo), and getChildAtIndex<Foo>(n)!$assertNodeType(getChildAtIndex(n), $isFoo). No logic changes, just type narrowing approach.

  3. Import cleanup: Removed unused concrete type imports (e.g. ParagraphNode, TextNode, TableNode) and added the corresponding type guard imports ($isParagraphNode, $isTextNode, $isTableNode). This is correct — the concrete types are no longer needed when using guards.

  4. Edge cases: The utility correctly handles null | undefined by coalescing to null before passing to the guard. One creative use in LexicalReconciler.test.ts uses a custom inline guard (node): node is TestDecoratorNode => node instanceof TestDecoratorNode — this is valid and shows the utility is flexible.

  5. www backwards compatibility: This PR only touches test files and a test utility. No production API changes, no export changes, no signature changes. Zero www impact.

  6. CI: Core unit tests (node 24.x) and core browser tests pass. CLA signed. Vercel previews deployed. Browser/e2e/integration tests still pending but those are test-only changes that should not regress.

Why this is safe: All changes are test-only. The deprecated generic type parameters still work in production code — this just migrates tests away from them so the deprecation can proceed. No runtime behavior change in any library package.

@etrepum etrepum added this pull request to the merge queue Jun 10, 2026
Merged via the queue into facebook:main with commit f18cff5 Jun 10, 2026
50 checks passed
@etrepum etrepum deleted the claude/cleanup-deprecated-code-t4z1j1 branch June 10, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants