Skip to content

Use generic for object-map Record key type#448

Open
sunnyzanchi wants to merge 1 commit intoangus-c:masterfrom
sunnyzanchi:object-map-types
Open

Use generic for object-map Record key type#448
sunnyzanchi wants to merge 1 commit intoangus-c:masterfrom
sunnyzanchi:object-map-types

Conversation

@sunnyzanchi
Copy link
Copy Markdown

This lets the function pass through more specific type information

✔️ Updated tests and yarn test-types passes

@angus-c
Copy link
Copy Markdown
Owner

angus-c commented Apr 30, 2022

Thanks! Is it possible for object key to be a number though? I think they can only be strings or symbols (all other values are automatically coerced to strings.

Comment thread packages/object-map/index.d.ts Outdated
item: Record<string, T>,
callback: (key: string, value: T) => U
): Record<string, U>;
declare function map<K extends string | number | symbol, T, U = T>(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think object keys can ever be numbers

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

hey! sorry for the late reply. you're right, that's my mistake. i updated the change to remove number from the type

This lets the function pass through more specific type information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants