Type rx.match as Component or Var depending on its cases
Gap
rx.match (Match.create) was declared -> Component | Var with no overloads. A function that returns rx.match(...) could be annotated as neither rx.Component nor Var, so downstream apps checked with ty or pyright had to add ignores.
Change
At runtime the first case's return value decides the result (_validate_return_types then requires every case to agree): a component builds a Match wrapped in a Fragment, anything else builds a Var. Match.create now has two overloads keyed on that first case, mirroring how rx.cond already splits component and var results:
- first case
tuple[Any, *tuple[Any, ...], BaseComponent]->Component - any other first case ->
Var
The second overload is broader than the first, so it carries the same reportOverlappingOverload ignore that cond uses. A call with no cases (which always raises at runtime) is now rejected statically; test_match_no_cond gets a reportCallIssue ignore for that.
New example: tests/type_checking/components_core.py.
Before
$ uv run ty check --python-version 3.14 tests/type_checking/components_core.py
error[invalid-return-type]: ... expected `Var[Unknown]`, found `Component | Var[Unknown]`
error[type-assertion-failure]: Argument does not have asserted type `Component`
error[type-assertion-failure]: Argument does not have asserted type `Var[Unknown]`
Found 4 diagnostics
$ uv run pyright tests/type_checking/components_core.py
... "Component | Var[Unknown]" is not assignable to return type "Var[Unknown]"
... "assert_type" mismatch: expected "Component" but received "Component | Var[Unknown]"
... "assert_type" mismatch: expected "Var[Unknown]" but received "Component | Var[Unknown]"
4 errors
After
$ uv run ty check --python-version 3.14 tests/type_checking/
All checks passed!
$ uv run pyright
0 errors, 2 warnings (pre-existing, tests/units/test_var.py)
uv run pytest tests/units -k match: 1990 passed.
š¤ Generated with Claude Code