-
Notifications
You must be signed in to change notification settings - Fork 841
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(api)!: Move TextMapPropagator<Carrier>
generic parameter to interface methods
#5368
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 file is where the main change occurred, the rest are updating the existing code/tests to work with this. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ import { Context } from '../context/types'; | |
* | ||
* @since 1.0.0 | ||
*/ | ||
export interface TextMapPropagator<Carrier = any> { | ||
export interface TextMapPropagator { | ||
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. Breaking change if you supplied a different type |
||
/** | ||
* Injects values from a given `Context` into a carrier. | ||
* | ||
|
@@ -43,7 +43,7 @@ export interface TextMapPropagator<Carrier = any> { | |
* @param setter an optional {@link TextMapSetter}. If undefined, values will be | ||
* set by direct object assignment. | ||
*/ | ||
inject( | ||
inject<Carrier>( | ||
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. Breaking change for most implementors |
||
context: Context, | ||
carrier: Carrier, | ||
setter: TextMapSetter<Carrier> | ||
|
@@ -61,7 +61,7 @@ export interface TextMapPropagator<Carrier = any> { | |
* @param getter an optional {@link TextMapGetter}. If undefined, keys will be all | ||
* own properties, and keys will be accessed by direct object access. | ||
*/ | ||
extract( | ||
extract<Carrier>( | ||
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. Breaking change for most implementors |
||
context: Context, | ||
carrier: Carrier, | ||
getter: TextMapGetter<Carrier> | ||
|
@@ -79,7 +79,7 @@ export interface TextMapPropagator<Carrier = any> { | |
* | ||
* @since 1.0.0 | ||
*/ | ||
export interface TextMapSetter<Carrier = any> { | ||
export interface TextMapSetter<Carrier> { | ||
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. Breaking change for someone referencing this type |
||
/** | ||
* Callback used to set a key/value pair on an object. | ||
* | ||
|
@@ -99,7 +99,7 @@ export interface TextMapSetter<Carrier = any> { | |
* | ||
* @since 1.0.0 | ||
*/ | ||
export interface TextMapGetter<Carrier = any> { | ||
export interface TextMapGetter<Carrier> { | ||
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. Breaking change for someone referencing this type |
||
/** | ||
* Get a list of all keys available on the carrier. | ||
* | ||
|
@@ -119,12 +119,12 @@ export interface TextMapGetter<Carrier = any> { | |
/** | ||
* @since 1.0.0 | ||
*/ | ||
export const defaultTextMapGetter: TextMapGetter = { | ||
export const defaultTextMapGetter: TextMapGetter<object | null | undefined> = { | ||
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 type changes here is also somewhat of a breaking change, though, it probably wouldn't have worked in practice if you tried to use it with anything else. |
||
get(carrier, key) { | ||
if (carrier == null) { | ||
return undefined; | ||
} | ||
return carrier[key]; | ||
return (carrier as Record<string, string>)[key]; | ||
}, | ||
|
||
keys(carrier) { | ||
|
@@ -138,12 +138,12 @@ export const defaultTextMapGetter: TextMapGetter = { | |
/** | ||
* @since 1.0.0 | ||
*/ | ||
export const defaultTextMapSetter: TextMapSetter = { | ||
export const defaultTextMapSetter: TextMapSetter<object | null | undefined> = { | ||
set(carrier, key, value) { | ||
if (carrier == null) { | ||
return; | ||
} | ||
|
||
carrier[key] = value; | ||
(carrier as Record<string, string>)[key] = value; | ||
}, | ||
}; |
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 suppose this signature change is also itself a breaking change, but code that would have stopped compiling after this change is probably broken IRL anyway. (Same for
extract
below.)This signature is also not really ideal –
Map
is anobject
,Headers
is anobject
too. None of those would work correctly if you don't also pass in a matchingsetter
(andgetter
in the case ofextract
), but the first overload would let it slide.We could change it to say
Carrier extends Record<string, string> | null | undefined
I suppose, I think that's technically more correct, but it is probably be too narrow for the intended ergonomic benefit here – a lot of types that you would want to pass into here and elide the setter/getter won't be accepted, and it would either require the caller to cast or explicitly import and pass the default setter/getter, which would be a shame.As it stands it's a compromise position, but not a bad one at that.