-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
Backport ReadonlyRecord & Record #1455
Conversation
We can't just change the signatures though, this PR contains the following breaking changes:
This was a mistake, thanks for pointing out (fixed now in v3) |
Oh, ok - I misunderstood the roadmap & the release process, my bad. Do you think it would make sense to add new functions w/ |
Yeah, I'm sorry, the roadmap wan't clear on this point, I put a "?" on the item list because I'm not even sure is possible to backport the new constraint. In general we can do whatever we want in the In the past I used the following technique:
Let's pick export const keys = <K extends string>(r: ReadonlyRecord<K, unknown>): ReadonlyArray<K> =>
(Object.keys(r) as any).sort() The new definition would be something like: declare const isOrd: (r: Ord<string> | ReadonlyRecord<string, unknown>) => r is Ord<string>
/**
* @since 2.5.0
*/
export function keys(O: Ord<string>): <K extends string>(r: ReadonlyRecord<K, unknown>) => ReadonlyArray<K>
/**
* Use the other overload instead
*
* @deprecated
*/
export function keys<K extends string>(r: ReadonlyRecord<K, unknown>): ReadonlyArray<K>
export function keys(
or: Ord<string> | ReadonlyRecord<string, unknown>
): ((r: ReadonlyRecord<string, unknown>) => ReadonlyArray<string>) | ReadonlyArray<string> {
return isOrd(or) ? keys(or) : (Object.keys(or) as any).sort()
} The problem is the |
No worries! Oh good question. Maybe something like this? const isOrd = (a: Record<string, unknown> | Ord<string>): a is Ord<string> =>
Object.keys(a).length === 2
&& 'equals' in a
&& typeof a.equals === 'function'
&& 'compare' in a
&& typeof a.compare === 'function' I know it's super kludgy, but we could probably assume that would work |
I would:
|
btw I know this is an horrible task, so feel free to close this PR or just clean it up by keeping only the new additions like |
cd364dc
to
6e8fc97
Compare
Not at all - it's my pleasure! It should be good now. By the way, I saw your comment in the Roadmap - please feel free to close this or steal from it if that'd be easier for you. Or I can remove the |
42ba631
to
372942a
Compare
372942a
to
93fca8e
Compare
@anthonyjoeseph awesome, thank you! |
Backports
ReadonlyRecord
from 3.0.0 based on the 2.11 roadmap #1446I agree w/ the
Ord
idea outlined in the roadmap, but I can change if desired.Notes:
Ord
constraints inRecord
as well, I can change it to useOrd.trivial
if desiredReadonlyRecord.wilt
andReadonlyRecord.wither
useOrd.trivial
in 3.0.0, but I mirrored that - I'm not sure if that was correctOrd
instances to these, which were unspecified - we can useOrd.trivial
instead if desiredtraverse
sequence
getShow
Traversable
->getTraversable: (O: Ord<string>) => ...
)