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

New: basic compare functions lt, lte, gt, gte #11

Merged
merged 8 commits into from
May 26, 2023
Merged

New: basic compare functions lt, lte, gt, gte #11

merged 8 commits into from
May 26, 2023

Conversation

Harris-Miller
Copy link
Collaborator

@Harris-Miller Harris-Miller commented Apr 1, 2023

This MR improves the typings for lt, lte, gt, and gte to include all Ord types

export type Ord = number | string | boolean | Date;

It also corrects the curry typing and removes the incorrect operand switching

// this is not correct!
export function gt(__: Placeholder): (b: number, a: number) => boolean;

Please note the addition and use of WidenLiterals. This is important only when you have

// when
export function gt<T extends Ord>(a: T): (b: T) => boolean;
gt(2)(1); // error: `T` is type literal `2`, and `1 !== 2`

// fix with `WidenLiterals`
export function gt<T extends Ord>(a: T): (b: WidenLiterals<T>) => boolean;
gt(2)(1); // ok! `T` is now `number`, and not `2`

The overloads orders are also updated so it's least to most arity. This is important because of how typescript used the last defined overload when accepting a function as an argument. When you do flip(lt) for example, in the previous order flip would have received the type (a: Ord) => (b: ord) = boolean. That is incorrect. The new ordering makes it so it receives (a: Ord, b: Ord) => boolean

To support that change an additional overload to the return type of flip had to be added for currying.

@Harris-Miller Harris-Miller changed the title Draft: New: basic compare functions lt, lte, gt, gte` Draft: New: basic compare functions lt, lte, gt, gte Apr 4, 2023
@Harris-Miller Harris-Miller changed the base branch from main to develop April 12, 2023 04:08
@Harris-Miller Harris-Miller mentioned this pull request Apr 27, 2023
@Harris-Miller Harris-Miller changed the title Draft: New: basic compare functions lt, lte, gt, gte New: basic compare functions lt, lte, gt, gte Apr 27, 2023
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.

1 participant