Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Added backwards compatible type supporting for events to have multiple values#105

Draft
Sam-Lee-17 wants to merge 1 commit intoclockwork-dog:mainfrom
Sam-Lee-17:allow-multiple-values-in-event-calls
Draft

Added backwards compatible type supporting for events to have multiple values#105
Sam-Lee-17 wants to merge 1 commit intoclockwork-dog:mainfrom
Sam-Lee-17:allow-multiple-values-in-event-calls

Conversation

@Sam-Lee-17
Copy link

@Sam-Lee-17 Sam-Lee-17 commented Jun 5, 2024

No description provided.

@Sam-Lee-17 Sam-Lee-17 changed the title Added backwards compatible type supporting for events to have multipl… Added backwards compatible type supporting for events to have multiple values Jun 5, 2024
@Sam-Lee-17 Sam-Lee-17 marked this pull request as draft June 5, 2024 23:05
Comment on lines 39 to 42
export type PluginManifestEventJson = {
name: string;
value?: CogsValueType;
value?: CogsValueType | { name: string; value: CogsValueType }[];
};
Copy link
Collaborator

@chetbox chetbox Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about?

/** @deprecated */
export type PluginManifestEventSingleParameterJson = {
  name: string;
  value?: CogsValueType;
};

export type PluginManifestEventMultiParameterJson = {
  name: string;
  value?: { name: string; value: CogsValueType }[];
};

export type PluginManifestEventJson = PluginManifestEventMultiParameterJson | PluginManifestEventSingleParameterJson;

Comment on lines 52 to 61
export type EventFromCogsAsObject<Manifest extends CogsPluginManifest> = DistributeObject<
{
[Name in EventNameFromCogs<Manifest>]: TypeFromCogsValueType<Extract<DeepMutable<EventFromCogs<Manifest>>, { name: Name }>['value']>;
[Name in EventNameFromCogs<Manifest>]:
Extract<DeepMutable<EventFromCogs<Manifest>>, { name: Name }> extends { name: Name; value: infer V extends CogsValueType } ? TypeFromCogsValueType<V> :
Extract<DeepMutable<EventFromCogs<Manifest>>, { name: Name }> extends { name: Name; value: infer V extends { name: string; value: CogsValueType }[] } ? DistributeObject<
{
[ValueName in V[number]['name']]: TypeFromCogsValueType<V[number]['value']>
}
> : undefined;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about separate utility types for the old and new version?

public readonly name: CogsEvent['name'],
public readonly value: CogsEvent extends { name: string; value: CogsValueType }
? ManifestTypes.TypeFromCogsValueType<CogsEvent['value']>
: CogsEvent extends { name: string; value: { name: string; value: CogsValueType }[] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. CogsEvent extends PluginManifestEventMultiParameterJson

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants