mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-21 02:40:08 +00:00
fix(bot): Bug with return type in functions (#4689)
* refactor(bot)!: setup desired properties for all transformers SetupDesiredProps when is given an object that does not corrispond to a transformer object that supports desired properties will behave like TransformProperty on the entire object as when it tries to get the properties for said object it will find `never` as the props and for `IsKeyDesired` a props of `never` means that all props are desired. * Use Equals helper, clean up a bit the code * Explicit the IsKeyDesired TProps never behavior * fix(bot): Bug with return type in functions
This commit is contained in:
@@ -550,6 +550,7 @@ export function createDesiredPropertiesObject<T extends RecursivePartial<Transfo
|
||||
webhookId: defaultValue,
|
||||
poll: defaultValue,
|
||||
call: defaultValue,
|
||||
resolved: defaultValue,
|
||||
...desiredProperties.message,
|
||||
},
|
||||
messageSnapshot: {
|
||||
@@ -1025,12 +1026,16 @@ export type TransformProperty<T, TProps extends TransformersDesiredProperties, T
|
||||
Equals<T, InteractionResolvedDataChannel<TransformersDesiredProperties, DesiredPropertiesBehavior>> extends true
|
||||
? // Yes, apply the desired props
|
||||
InteractionResolvedDataChannel<TProps, TBehavior>
|
||||
: // Is it an object?
|
||||
IsObject<T> extends true
|
||||
? // Yes, we need to ensure we transform the nested properties as well
|
||||
{ [K in keyof T]: TransformProperty<T[K], TProps, TBehavior> }
|
||||
: // No, this is a normal value such as string / bigint / number
|
||||
T;
|
||||
: // Is it a function?
|
||||
T extends (...args: infer P) => Promise<infer R>
|
||||
? // Yes, we need to ensure we transform the return type as well
|
||||
(...args: P) => Promise<TransformProperty<R, TProps, TBehavior>>
|
||||
: // Is it an object?
|
||||
IsObject<T> extends true
|
||||
? // Yes, we need to ensure we transform the nested properties as well
|
||||
{ [K in keyof T]: TransformProperty<T[K], TProps, TBehavior> }
|
||||
: // No, this is a normal value such as string / bigint / number
|
||||
T;
|
||||
|
||||
/**
|
||||
* Apply desired properties to an object.
|
||||
|
||||
@@ -1297,10 +1297,8 @@ export interface Message {
|
||||
tts: boolean;
|
||||
/** Whether this message came from the urgent message system */
|
||||
urgent: boolean;
|
||||
// TODO: Adding this causes errors in the interaction functions due to how `InteractionResolvedDataMember` and `InteractionResolvedDataChannel` are treated by `TransformProperty`, since they get their desired props changed
|
||||
// and fixing this requires a few changes in `SetupDesiredProps` and `TransformProperty` so this is going to be done in another pr
|
||||
// /** data for users, members, channels, and roles referenced in this message */
|
||||
// resolved?: InteractionDataResolved
|
||||
/** data for users, members, channels, and roles referenced in this message */
|
||||
resolved?: InteractionDataResolved;
|
||||
}
|
||||
|
||||
export interface MessageActivity {
|
||||
|
||||
Reference in New Issue
Block a user