radashi-org / radashi

The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.
https://radashi.js.org
MIT License
314 stars 25 forks source link

fix(types): `mapValues` index signature handling #297

Closed aleclarson closed 3 weeks ago

aleclarson commented 3 weeks ago

[!TIP] The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

mapValues was incorrectly handling index signatures at the type level:

// BEFORE
const object = mapValues({} as { [key: string]: number }, x => String(x))
//    ^? { [key: string]: string; [key: number]: string }

// AFTER
const object = mapValues({} as { [key: string]: number }, x => String(x))
//    ^? { [key: string]: string }

For any code change,

Does this PR introduce a breaking change?

No

aleclarson commented 3 weeks ago

Also fixed handling of optional properties when exactOptionalPropertyTypes is true in your tsconfig.

For example, if the mapped object is of type { a?: number }, the mapping function will now receive a number instead of number | undefined.

radashi-bot commented 3 weeks ago

A stable release 12.2.1 has been published to NPM. :rocket:

To install:

pnpm add radashi@12.2.1

See the changes