fix: widen mutable property literal types - #11297
Conversation
🦋 Changeset detectedLatest commit: e38cd48 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
WalkthroughProperty initialisers now widen literal bigint, boolean, number, string, and template values to their primitive types. Object and regular-expression literals retain literal types. Class and object property inference uses this widening. Valid cases cover mutable object properties and private class fields. A patch changeset documents the Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_js_type_info/src/local_inference.rs (1)
1904-1930: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd rustdoc for the widening contract.
Document both helpers with
///comments. State which primitive literal types widen, and why object and regular-expression literals remain literal types.As per coding guidelines, use rustdoc for new rule changes and document contracts for future contributors.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/biome_js_type_info/src/local_inference.rs` around lines 1904 - 1930, Add rustdoc comments to reference_to_widened_property_value and widen_property_value_type_data describing that bigint, boolean, number, string, and template literals widen to their primitive types, while object and regular-expression literals remain literal types to preserve their structural or identity-specific information.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/biome_js_type_info/src/local_inference.rs`:
- Around line 1904-1930: Add rustdoc comments to
reference_to_widened_property_value and widen_property_value_type_data
describing that bigint, boolean, number, string, and template literals widen to
their primitive types, while object and regular-expression literals remain
literal types to preserve their structural or identity-specific information.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c060588d-fa3b-4da9-a0f3-9cc243559eb5
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/suspicious/noUnnecessaryConditions/valid.ts.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (3)
.changeset/witty-badgers-widen.mdcrates/biome_js_analyze/tests/specs/suspicious/noUnnecessaryConditions/valid.tscrates/biome_js_type_info/src/local_inference.rs
Merging this PR will degrade performance by 14.63%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Fixes #11174.
This widens primitive literal initializers for mutable object/class properties, so
noUnnecessaryConditionsdoes not treat checks likeguard.currentafter{ current: false }as permanently falsy.Added regression coverage for object and class properties.
@ematipico this follows up on the confirmed issue.
AI assistance disclosure: I used AI assistance to inspect the relevant inference path and draft the patch; I reviewed the changes and ran the focused checks locally.