Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): mapValues index signature handling #297

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Nov 7, 2024

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,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

@aleclarson
Copy link
Member Author

aleclarson commented Nov 7, 2024

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.

@aleclarson aleclarson merged commit 2ade9be into main Nov 7, 2024
8 checks passed
@aleclarson aleclarson deleted the fix/mapValues-index-signature branch November 7, 2024 21:12
@radashi-bot
Copy link

A stable release 12.2.1 has been published to NPM. 🚀

To install:

See the changes

MarlonPassos-git pushed a commit to MarlonPassos-git/radashi that referenced this pull request Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants