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(object): the return type of objectMap should be the return type o… #46

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import type { DeepMerge } from './types'
* // { b: 2 }
* ```
*/
export function objectMap<K extends string, V, NK = K, NV = V>(obj: Record<K, V>, fn: (key: K, value: V) => [NK, NV] | undefined): Record<K, V> {
export function objectMap<K extends string, V, NK extends string | number | symbol = K, NV = V>(obj: Record<K, V>, fn: (key: K, value: V) => [NK, NV] | undefined): Record<NK, NV> {
Copy link

@nandordudas nandordudas Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for curiosity, what do you think using of PropertyKey instead of string | number | symbol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for curiosity, what do you think using of PropertyKey instead of string | number | symbol?

This idea of yours is better I think. I use string | number | symbol just because that's what VSCode suggests.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the honest answer.

return Object.fromEntries(
Object.entries(obj)
.map(([k, v]) => fn(k as K, v as V))
.filter(notNullish),
)
) as Record<NK, NV>
}

/**
Expand Down