Skip to content

feat(type-info): add Pick and Omit type synthesis#9874

Merged
ematipico merged 12 commits intobiomejs:mainfrom
minseong0324:feat/type-pick-omit-synthesis
Apr 13, 2026
Merged

feat(type-info): add Pick and Omit type synthesis#9874
ematipico merged 12 commits intobiomejs:mainfrom
minseong0324:feat/type-pick-omit-synthesis

Conversation

@minseong0324
Copy link
Copy Markdown
Contributor

I used Claude Code to assist with this implementation.

Summary

Addresses items from #9810: synthesizes Pick<T, K> and Omit<T, K> following the existing Record<K, V> pattern.

Resolves T, extracts string literal keys from K, and filters members accordingly. Falls back to generic instantiation when T or K can't be resolved.

Test Plan

Snapshot tests.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: 438a40b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

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

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Type-Inference Area: type inference labels Apr 9, 2026
@minseong0324 minseong0324 marked this pull request as ready for review April 9, 2026 01:04
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 9, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 196 skipped benchmarks1


Comparing minseong0324:feat/type-pick-omit-synthesis (438a40b) with main (bcd6508)

Open in CodSpeed

Footnotes

  1. 196 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

Walkthrough

Adds Pick/Omit-aware resolution to the type resolver: when a TypeReferenceQualifier is Pick<T, K> or Omit<T, K> with two type parameters, the resolver resolves T, extracts string-literal keys from K, and filters T’s own members (Pick keeps members matching keys; Omit removes matching keys and retains unnamed members). Falls back to prior behaviour if K can’t be extracted or T isn’t object-like. Adds is_pick/is_omit predicates and expands many analyzer tests to cover Pick/Omit cases.

Possibly related PRs

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding Pick and Omit type synthesis to the type-info module.
Description check ✅ Passed The description provides a clear summary of what was implemented, how it works, and references the related issue, directly corresponding to the changeset across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/type-pick-omit-synthesis

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

The synthesis of Pick and Omit has definitely repercussions on some of our type-aware lint rules. This means:

  • we should add more tests for the other lint rules (it seems to added tests for one already)
  • we must have a changeset, notably focused towards what the lint rules can do now

Comment thread crates/biome_js_type_info/src/resolver.rs
@minseong0324 minseong0324 force-pushed the feat/type-pick-omit-synthesis branch 3 times, most recently from 1ec79bc to 38748cf Compare April 10, 2026 23:50
@minseong0324 minseong0324 force-pushed the feat/type-pick-omit-synthesis branch from 38748cf to af11c8a Compare April 11, 2026 18:25
@minseong0324
Copy link
Copy Markdown
Contributor Author

The synthesis of Pick and Omit has definitely repercussions on some of our type-aware lint rules. This means:

  • we should add more tests for the other lint rules (it seems to added tests for one already)
  • we must have a changeset, notably focused towards what the lint rules can do now

@ematipico Added test cases for the 8 type-aware rules in c96f270, and the changeset in 61ac64d.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/biome_js_analyze/tests/specs/nursery/noUselessTypeConversion/invalid.ts (1)

58-67: Optional: add Omit parity for number/boolean too.

You already cover Pick for number/boolean; adding matching Omit variants would make regressions even harder to sneak in. Not required, just a tidy completeness win.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@crates/biome_js_analyze/tests/specs/nursery/noUselessTypeConversion/invalid.ts`
around lines 58 - 67, Add matching Omit test cases for the number and boolean
cases to mirror the existing Pick variants: declare an omittedNum using Omit<{
n: number; s: string }, "s"> and call Number(omittedNum.n) and reference
omittedNum.n (mirroring pickedNum), and declare an omittedFlag using Omit<{
flag: boolean; label: string }, "label"> and call Boolean(omittedFlag.flag) and
use !!omittedFlag.flag (mirroring pickedBool); place these next to the existing
omittedStr / pickedNum / pickedBool blocks so the number/boolean Omit parity is
covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@crates/biome_js_analyze/tests/specs/nursery/noUselessTypeConversion/invalid.ts`:
- Around line 58-67: Add matching Omit test cases for the number and boolean
cases to mirror the existing Pick variants: declare an omittedNum using Omit<{
n: number; s: string }, "s"> and call Number(omittedNum.n) and reference
omittedNum.n (mirroring pickedNum), and declare an omittedFlag using Omit<{
flag: boolean; label: string }, "label"> and call Boolean(omittedFlag.flag) and
use !!omittedFlag.flag (mirroring pickedBool); place these next to the existing
omittedStr / pickedNum / pickedBool blocks so the number/boolean Omit parity is
covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6456471d-6337-4d7a-9e3b-1613861cc18f

📥 Commits

Reviewing files that changed from the base of the PR and between 09bf57e and af11c8a.

⛔ Files ignored due to path filters (8)
  • crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/noMisusedPromises/checksConditionalsInvalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/noUnnecessaryConditions/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/noUnsafePlusOperands/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/noUselessTypeConversion/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useExhaustiveSwitchCases/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useNullishCoalescing/invalid.ts.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (10)
  • .changeset/smooth-ideas-write.md
  • crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/noMisusedPromises/checksConditionalsInvalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/noUnnecessaryConditions/invalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/noUnsafePlusOperands/invalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/noUselessTypeConversion/invalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/useExhaustiveSwitchCases/invalid.ts
  • crates/biome_js_analyze/tests/specs/nursery/useNullishCoalescing/invalid.ts
  • crates/biome_js_type_info/src/resolver.rs
✅ Files skipped from review due to trivial changes (1)
  • .changeset/smooth-ideas-write.md

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you! Need to fix the merge conflicts

Comment on lines +968 to +978
let mut names = Vec::new();
for ty in union.types() {
let resolved = resolver.resolve_and_get(ty)?;
let TypeData::Literal(lit) = resolved.to_data() else {
return None;
};
let Literal::String(s) = lit.as_ref() else {
return None;
};
names.push(s.as_ref().clone());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can be a written using types().filter_map().collect()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in f215a04. Used .iter() before filter_map since types() returns a slice.

@minseong0324 minseong0324 force-pushed the feat/type-pick-omit-synthesis branch from 9321c99 to f215a04 Compare April 12, 2026 13:48
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/biome_js_type_info/src/resolver.rs`:
- Around line 845-850: When synthesising Pick/Omit objects you're currently
hardcoding prototype: None in the TypeData::Object creation (inside the
resolver.register_and_resolve call); instead fetch and preserve the original
object's prototype value and use it when creating the new Object so prototype
metadata isn't lost. Locate where members is derived and the original
TypeData/Object instance for T, extract its prototype (e.g.
original_object.prototype or similar) and pass that value into the new Object's
prototype field rather than None; keep using members.into() for members and
ensure any Clone or ownership adjustments are handled.
- Around line 967-982: The current TypeData::Union arm uses filter_map which
silently drops non-string members and returns Some(vec) even if some union
members are invalid; change the logic in the TypeData::Union branch (the block
that calls resolver.resolve_and_get for each ty) to fail the whole operation
when any union member is not a Literal::String: iterate over union.types(), call
resolver.resolve_and_get(ty) for each, check that resolved.to_data() matches
TypeData::Literal and that lit is Literal::String, and if any check fails return
None; otherwise collect the string values into a Vec and return Some(vec).
Ensure you reference the same symbols (TypeData::Union,
resolver.resolve_and_get, TypeData::Literal, Literal::String) when applying the
fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a9772a79-ea38-4b19-abfc-3b25adebfc83

📥 Commits

Reviewing files that changed from the base of the PR and between 9321c99 and f215a04.

📒 Files selected for processing (1)
  • crates/biome_js_type_info/src/resolver.rs

Comment on lines +845 to +850
if let Some(members) = members {
let resolved_id: ResolvedTypeId = resolver.register_and_resolve(
TypeData::Object(Box::new(Object {
prototype: None,
members: members.into(),
})),
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.

⚠️ Potential issue | 🟠 Major

Preserve the prototype when synthesising Pick/Omit objects

Line 848 hardcodes prototype: None. If T is an object with a prototype, that information is lost in the synthesised type.

Proposed fix
-                            if let Some(members) = members {
+                            if let Some(members) = members {
+                                let prototype = match &t_data {
+                                    TypeData::Object(object) => object.prototype.clone(),
+                                    _ => None,
+                                };
                                 let resolved_id: ResolvedTypeId = resolver.register_and_resolve(
                                     TypeData::Object(Box::new(Object {
-                                        prototype: None,
+                                        prototype,
                                         members: members.into(),
                                     })),
                                 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_js_type_info/src/resolver.rs` around lines 845 - 850, When
synthesising Pick/Omit objects you're currently hardcoding prototype: None in
the TypeData::Object creation (inside the resolver.register_and_resolve call);
instead fetch and preserve the original object's prototype value and use it when
creating the new Object so prototype metadata isn't lost. Locate where members
is derived and the original TypeData/Object instance for T, extract its
prototype (e.g. original_object.prototype or similar) and pass that value into
the new Object's prototype field rather than None; keep using members.into() for
members and ensure any Clone or ownership adjustments are handled.

Comment thread crates/biome_js_type_info/src/resolver.rs
…-synthesis

# Conflicts:
#	crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/invalid.ts
#	crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/invalid.ts.snap
#	crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts
#	crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts.snap
@minseong0324 minseong0324 requested a review from ematipico April 12, 2026 14:45
@github-actions github-actions Bot added the A-Project Area: project label Apr 13, 2026
@minseong0324 minseong0324 force-pushed the feat/type-pick-omit-synthesis branch from 0939aa7 to 438a40b Compare April 13, 2026 12:42
@minseong0324
Copy link
Copy Markdown
Contributor Author

Thank you! Need to fix the merge conflicts

@ematipico Resolved merge conflicts in 438a40b.

@ematipico ematipico merged commit 9e570d1 into biomejs:main Apr 13, 2026
18 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter A-Project Area: project A-Type-Inference Area: type inference L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants