fix(map, mapWithFeedback): Correct types through NoInfer#1368
Conversation
|
|
✅ Deploy Preview for trusting-lumiere-9c7fad ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1368 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 175 175
Lines 1648 1648
Branches 405 405
=========================================
Hits 1648 1648 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
commit: |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the internal Mapped<T, K> type used by map/mapWithFeedback to avoid a TypeScript inference edge case where arrays flowing through NoInfer<T> stop behaving like normal arrays in downstream generic constraints (e.g. sortBy), while preserving tuple “shape” behavior.
Changes:
- Update
Mapped<T, K>to short-circuit toK[]whenTis effectively a “simple array” (T[number][] extends T), avoiding a broken mapped-type result inNoInferscenarios. - Add type-level regression tests for
maparound empty/optional tuples and theNoInfer→sortBypipeline case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/remeda/src/map.test-d.ts | Adds type regression coverage for empty/optional tuples and the NoInfer inference issue flowing into sortBy (including pipe/data-last). |
| packages/remeda/src/internal/types/Mapped.ts | Changes Mapped to fall back to K[] for simple arrays to avoid TypeScript mapped-type inference failures with NoInfer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🎉 This PR is included in version 2.39.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |

Fixes: #1364
When an array is typed through a NoInfer (as in the attached issue) it fails to map properly via mapped types (while still being inferred as an array). To work around this we short-circuit our mapped type for simple arrays.