-
Notifications
You must be signed in to change notification settings - Fork 528
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
Jsonable to support interfaces #1816
Conversation
@@ -26,4 +29,8 @@ export type JsonableArray<T> = Jsonable<T>[]; | |||
* - Non-finite numbers (`NaN`, `+/-Infinity`) are also coerced to `null`. | |||
* - (`null` always serializes as `null`.) | |||
*/ | |||
export type Jsonable<T = JsonablePrimitive> = T | JsonableArray<T> | JsonableObject<T>; | |||
export type Jsonable<T> = { | |||
[P in keyof T]: T[P] extends JsonablePrimitiveArrayOrObject |
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 just pushed a PR for basically the same thing 😋 check it out #1823
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 think this might be too loose. Does it fail if an interface isn't jsonable?
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.
Yes, it covers all the scenarios I could think of
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.
Something something... great minds think alike. lol
I think I like this one because the consumption syntax is much simpler and only uses the one type:
function foo<T extends Jsonable<T>>(a: T): void {
}
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.
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 think we need type recursion to make this work
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.
mine fails with that too
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 approve of both. :-)
Slight preference for end-user ergonomics of the grand unified Jsonable<T>
approach, if the results are comparable.
closing on account of Tony's PR #1823 |
Let Jsonable support interfaces