-
Notifications
You must be signed in to change notification settings - Fork 75
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
feat(common): Improve objectMap typing #2730
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all looks reasonable, but tsc is often unreasonable so without tests I'm not 100% sure it does work.
Edit: oh I see Agoric/agoric-sdk#11064
* const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>, | ||
* >( | ||
* entries: Entries, | ||
* ) => { [Entry in Entries[number] as Entry[0]]: Entry[1] }} FromTypedEntries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const mapEntry = ([k, v]) => [k, mapFn(v, k)]; | ||
const newEntries = typedMap(oldEntries, mapEntry); | ||
const newObj = fromTypedEntries(newEntries); | ||
return /** @type {any} */ (harden(newObj)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did it stick here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure; it seems to have just gotten super confused:
Type '{ [Entry in [keyof O, R] as Entry[0]]: Entry[1]; }' is not assignable to type '{ [K in keyof O]: K extends string ? R : never; }'.
Type 'keyof O' is not assignable to type '[keyof O, R]'.
Type 'string | number | symbol' is not assignable to type '[keyof O, R]'.
Type 'string' is not assignable to type '[keyof O, R]'.(2322)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the type mapping failing ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly microsoft/TypeScript#49653 (comment) ?
Description
Inspired by Agoric/agoric-sdk#11040 , try to type
objectMap
more precisely. I'm interested to see what this breaks.agoric-sdk integration PR: Agoric/agoric-sdk#11064