Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Annotate the map type argument, not the result array
When a map transform needs an explicit output contract, prefer a map type argument or callback return annotation that checks each produced object.
Bad example
| 1 | const authors: PersonLeaf[] = article.authors.map((author) => ({ |
| 2 | '@type': 'Person', |
| 3 | name: author.fullname, |
| 4 | })); |
| 5 | // error (if any) points at the whole array assignment |
Explanation (EN)
A callback-local constraint makes the intended output shape visible where fields are assembled.
Objašnjenje (HR)
Ograničenje na razini callbacka pokazuje očekivani izlazni oblik ondje gdje se polja sastavljaju.
Good example
| 1 | const authors = article.authors.map<PersonLeaf>((author) => ({ |
| 2 | '@type': 'Person', |
| 3 | name: author.fullname, |
| 4 | })); |
| 5 | // error points at the exact bad field inside the callback |
Explanation (EN)
The map<T>() type argument constrains the callback return, so TypeScript flags the precise field that does not fit.
Objašnjenje (HR)
Tipski argument map<T>() ogranicava povratnu vrijednost callbacka, pa TypeScript oznaci tocno polje koje ne odgovara.
Notes (EN)
For a map transform that must produce a specific structural type, place its constraint near the callback and inspect the actual compiler diagnostic.
Exceptions / Tradeoffs (EN)
Inference, satisfies or an explicit callback return type may already provide a precise constraint. A destination annotation can also contextualize the result; diagnostic placement depends on the expression.