You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f692ec2
Browse filesBrowse the repository at this point in the historyBrowse files
fix(types): permissive props for un-introspectable targets, plus as-target autocomplete while typing (#5758)
* fix(types): keep styled() and .attrs() permissive for un-introspectable targets
Wrapping a component whose props can't be statically read -- most notably
Mantine v7's polymorphic-factory components (Button, Card, Menu.Item),
whose generic callable signature defeats React.ComponentPropsWithRef and
collapses to {} -- made the resulting styled component reject every prop,
including children, at the JSX call site and via .attrs().
Detect the un-introspectable case and widen to a permissive prop bag for it
alone; targets with readable prop types keep full checking. The widening is
confined to the JSX call surface, never the statics or defaultProps, so the
real Props can't leak past the call site. The "no known keys" test is
distributed over the prop type first so a bare union of disjoint shapes
(keyof intersects to never despite being introspectable) isn't widened by
mistake.
Closes#5756
* fix(types): collapse polymorphic overloads to one signature so as-target completion survives mid-typing
A partially-typed or unknown attribute on a polymorphic styled component
(e.g. <Comp as="video" foo l|>) matched none of the call overloads, so
overload resolution failed and JSX attribute completion dropped to nothing
-- the as-target's props (video's loop/controls/...) disappeared while
typing. Replacing the overload set with a single conditional call signature
keeps completion resolved at all times.
The branching (PolymorphicCallProps) preserves prior behavior: a real
as-target substitutes its props; no-as / wrapped-as (Url-typed) keeps
Substitute-free base props for ref inference on spread (#5687), wrapped-as
assignability (#5734), and plain completion (#5741); forwardedAs substitutes
the forwarded target.
The single signature instantiates a conditional per JSX usage where the
overload set resolved plain usage to a free non-generic overload, so some
extra type work is inherent. Two changes keep it small: the target test uses
string | AnyComponent rather than the literal-heavy WebTarget (same set,
~6% fewer instantiations across call sites), and the no-target result is a
shared alias so it instantiates once. Net vs the prior overloads:
instantiations 1,608,782 -> 1,696,358 (+5.4%), check time 2.94s -> 3.22s.
Fix a TypeScript error when wrapping a component whose props can't be statically read, such as Mantine v7's polymorphic-factory components (`Button`, `Card`, `Menu.Item`, and similar). These styled components no longer reject every prop, including `children`; arbitrary props are accepted again at the JSX call site and via `.attrs()`, while components with readable prop types stay fully type-checked.
Keep TypeScript attribute autocomplete working while you type props on a polymorphic styled component. When a component renders a different element through `as` (for example `as="video"`), beginning to type a new prop name could make the whole suggestion list vanish; the rendered element's props now keep autocompleting as you go.
0 commit comments