Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Narrow forwarded prop bags with `Omit` to protect wrapper-controlled props
When forwarding a child component's props, `Omit` the props the wrapper manages so callers can't override and break them.
Bad example
| 1 | interface ButtonProps { |
| 2 | onClick: () => void; |
| 3 | // forwards the full prop bag, so callers can override `type` and `onClick` |
| 4 | innerProps?: HTMLButtonProps; |
| 5 | } |
Explanation (EN)
Forwarding the full prop bag lets callers override props the wrapper is supposed to control, silently breaking the component's invariants.
Objašnjenje (HR)
Prosljedivanje cijelog skupa propova dopusta pozivateljima da prepisu propove koje bi wrapper trebao kontrolirati, tiho rusenje invarijanti komponente.
Good example
| 1 | type InnerProps = Omit<HTMLButtonProps, 'type' | 'onClick'>; |
| 2 |
|
| 3 | interface ButtonProps { |
| 4 | onClick: () => void; |
| 5 | innerProps?: InnerProps; |
| 6 | } |
Explanation (EN)
Omitting the wrapper-controlled props from the forwarded type makes it impossible for callers to override them, keeping the component's behavior guaranteed by the type system.
Objašnjenje (HR)
Izostavljanje propova koje wrapper kontrolira iz proslijedenog tipa onemogucuje pozivateljima da ih prepisu, cuvajuci ponasanje komponente zajamceno tipskim sustavom.