-
Notifications
You must be signed in to change notification settings - Fork 616
fix(types): extends check of generic in WithSdkStreamMixin #4119
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
Conversation
Fix an issue where WithSdkStreamMixin would apply to more properties than intended due to Distributive Conditional Types.
@trivikr Does your builds get cached? Seems it's the same build. Is the title better now? |
packages/types/src/serde.ts
Outdated
@@ -92,7 +92,7 @@ export type SdkStream<BaseStream> = BaseStream & SdkStreamMixin; | |||
* with the SdkStreamMixin helper methods. | |||
*/ | |||
export type WithSdkStreamMixin<T, StreamKey extends keyof T> = { | |||
[key in keyof T]: T[key] extends T[StreamKey] ? SdkStream<T[StreamKey]> : T[key]; | |||
[key in keyof T]: [T[key]] extends [T[StreamKey]] ? SdkStream<T[StreamKey]> : T[key]; |
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.
[key in keyof T]: [T[key]] extends [T[StreamKey]] ? SdkStream<T[StreamKey]> : T[key]; | |
[key in keyof T]: key extends StreamKey ? SdkStream<T[StreamKey]> : T[key]; |
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.
type Stream = {} | undefined;
type Data = {
undef: undefined
num: number
str: string
stream: Stream
}
type Mixin<T> = T & {
someAddedMethod(): void
}
// for v1/v2, the match is on the type of the key indicated. This is too wide if the Stream type includes undefined.
type ApplyConditionalTypeMappingV1<T, Key extends keyof T> = {
[key in keyof T]: T[key] extends T[Key] ? Mixin<T[Key]> : T[key];
}
type ApplyConditionalTypeMappingV2<T, Key extends keyof T> = {
[key in keyof T]: [T[key]] extends [T[Key]] ? Mixin<T[Key]> : T[key];
}
// this applies the type mixin only to the specified key.
type ApplyConditionalTypeMappingV3<T, Key extends keyof T> = {
[key in keyof T]: key extends Key ? Mixin<T[Key]> : T[key];
}
const data: ApplyConditionalTypeMappingV3<Data, 'stream'> = {
num: 1,
str: 'a',
stream: undefined,
undef: undefined,
}
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.
Agreed that this is more robust
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.
Updated docs, however this does change the behaviour and I'm not sure if the change from matching multiple keys to only a single key is expected (even though the signature of the mixin definitely indicates it only should match one key). But I'll leave that up to you maintainers :)
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, there will only be one key. I believe this is guaranteed by Smithy.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Fix an issue where WithSdkStreamMixin would apply to more properties than intended due to Distributive Conditional Types.
Issue
#4111
Description
Fix an issue where WithSdkStreamMixin would apply to more properties than intended due to Distributive Conditional Types.
Testing
Tested locally with client-s3 and it's GetObjectCommand-output which now correctly only applies the mixin on "Body".
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.