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).
Annotate the map type argument, not the result array
Type a transform via the .map<T>() type argument rather than annotating the destination variable. The type argument constrains the callback's return so a mismatch is reported on the offending field inside the callback, not as a vague whole-array assignment error.
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)
Annotating the result array reports a mismatch as a single assignment error, hiding which property in the object literal is wrong.
Objašnjenje (HR)
Anotiranje rezultirajuceg niza prijavljuje neslaganje kao jednu gresku dodjele, skrivajuci koje je svojstvo u objektu pogresno.
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.