-
-
Notifications
You must be signed in to change notification settings - Fork 240
Add error
property to "degraded" events
#6188
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
Changes from all commits
889b5df
1e29c44
7dc0e90
4693d47
8379d0e
54cf37f
0b19e79
611dc37
25772fc
19968e3
e51abf5
b891700
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,5 @@ export type FetchOptions = RequestInit; | |
*/ | ||
export type AddToCockatielEventData<EventListener, AdditionalData> = | ||
EventListener extends (data: infer Data) => void | ||
? // Prevent Data from being split if it's a type union | ||
[Data] extends [void] | ||
? (data: AdditionalData) => void | ||
: (data: Data & AdditionalData) => void | ||
? (data: Data extends void ? AdditionalData : Data & AdditionalData) => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was an interesting one to figure out. The purpose of this utility type is to extend the type for a Cockatiel event with additional payload data. We need to do this because However, this type did not properly account for when If we say the following AddToCockatielEventData<
(data: void | { error: Error } | { value: unknown }) => void,
{ foo: 'bar' }
> we want this to resolve to: (data: { foo: 'bar' } | ({ error: Error } & { foo: 'bar' }) | ({ value: unknown } & { foo: 'bar' })) => void (Essentially, we want the But instead this was resolving as: (data: ((void | { error: Error } | { value: unknown }) & { foo: 'bar' }) => void which distributes to: (data: (void & { foo: 'bar' }) | ({ error: Error } & { foo: 'bar' }) | ({ value: unknown } & { foo: 'bar' })) => void This is incorrect, because What we want is for TypeScript to distribute But the second thing is that even if we say Even if the condition were in the place we wanted it, TypeScript seems to distribute the type union only in a particular circumstance. Looking a bit deeper at the TypeScript 2.8 release notes where this concept was introduced, it says: "Distributive conditional types are automatically distributed over union types during instantiation." In this case, we also need to place the condition so it becomes a part of the type that we want to "return" from this utility type and is not used to simply determine the return type. This way TypeScript evaluates the condition when that return type is used and not beforehand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change make sense. |
||
: never; |
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.
Should this be Changed ? because it feels a bit strange to have under Added section Update as a first keyword ?
Uh oh!
There was an error while loading. Please reload this page.
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.
The Keep a Changelog spec says that "Added" is for new features and "Changed" is for changes in existing functionality. I've always found this to be a bit lacking, though.
The way I've been treating "Changed" is that it is for changes in existing behavior or functionality that do not come with changes to the API itself. For instance, maybe a method was updated so that the logic is different but returns data in the same shape. "Added", on the other hand, is for changes that extend the API in some way, so this could be something larger like a new class, function, method, etc. but also something smaller like a new argument or a new property on a type.
I guess I could have said something like:
Would that sound like it fits better? Or what is your view on Added vs. Changed?
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 looks good