Skip to content

fix(extract): skip declare ambient class properties in class-member extraction#849

Open
BartWaardenburg wants to merge 3 commits into
mainfrom
fix/issue-839-declare-class-member
Open

fix(extract): skip declare ambient class properties in class-member extraction#849
BartWaardenburg wants to merge 3 commits into
mainfrom
fix/issue-839-declare-class-member

Conversation

@BartWaardenburg
Copy link
Copy Markdown
Collaborator

DRAFT: Reviewer verdict was FIX. The following must be resolved before merge:

  • Bump CACHE_VERSION from 106 to 107 in crates/extract/src/cache/types.rs (line 108) and add a doc paragraph explaining that pre-fix caches may retain the declare member as unused until the file is re-extracted.

Summary

Added a && !prop.declare guard in the ClassElement::PropertyDefinition arm of extract_class_members in crates/extract/src/visitor/helpers.rs. TypeScript declare properties are ambient-only (no emitted JS) and cannot be value-referenced, so they must not appear as extracted class members. The regression test declare_ambient_property_excluded_from_class_members parses a class with a declare readonly __input?: I field plus a normal method and asserts the ambient field is absent from extracted members while the method is present.

Review

Verdict: FIX

  • Missing CACHE_VERSION bump. extract_class_members output is persisted in the parse cache (CachedExport.members: Vec<CachedMember> in crates/extract/src/cache/types.rs:326, CACHE_VERSION=106). The fix changes the content of cached member data (now omits the declare member), an extraction-semantics change. Without bumping 106 to 107, a user upgrading to get this fix keeps the stale cached __input member and the false unused-class-member finding persists across the upgrade until each affected file is touched. The assertion at cache/types.rs:145 explicitly triggers on "wire shape OR extraction semantics."
  • Non-blocking: the core guard, test, clippy, and fmt are all clean and correct. Only the cache-version omission blocks merge.

Closes #839

- Bump extract CACHE_VERSION 107 -> 108: skipping declare ambient
  class members changes the persisted CachedExport.members shape, so
  warm caches would otherwise retain the false unused-class-member
  finding across upgrade.
- Add CHANGELOG entry under Unreleased/Fixed.
- Add detection.md note for the declare exclusion.
@BartWaardenburg BartWaardenburg force-pushed the fix/issue-839-declare-class-member branch from 7d7f952 to 9e303a4 Compare June 1, 2026 21:50
@BartWaardenburg BartWaardenburg marked this pull request as ready for review June 1, 2026 21:50
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.

unused-class-member false positive on TypeScript declare (ambient) class properties

1 participant