Skip to content

Commit

Permalink
fix: improve AST parsing of aliased indexed types (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Herman <geekyeggo@users.noreply.github.com>
  • Loading branch information
GeekyEggo and GeekyEggo authored Sep 9, 2024
1 parent 0af1f4f commit dd2f9e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ export function get(path: string, source: unknown): unknown {
const props: string[] = path.split(".");
return props.reduce((obj, prop) => obj && obj[prop as keyof object], source);
}

/**
* Utility type that acts as an alternate for `type[key]`. This type provides better support for aliasing
* types when parsing them using the abstract syntax tree, used when generating documentation.
*/
export type KeyOf<T, K extends keyof T> = Omit<T[K], "">;
7 changes: 4 additions & 3 deletions src/plugin/actions/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JsonObject, JsonValue } from "..";
import type streamDeck from "../";
import type { ActionIdentifier, DidReceiveSettings, FeedbackPayload, SetImage, SetTitle, SetTriggerDescription, State } from "../../api";
import type { KeyOf } from "../../common/utils";
import { connection } from "../connection";
import { ActionContext } from "./context";
import type { SingletonAction } from "./singleton-action";
Expand Down Expand Up @@ -242,14 +243,14 @@ export class Action<T extends JsonObject = JsonObject> extends ActionContext {
/**
* Options that define how to render an image associated with an action.
*/
export type ImageOptions = Omit<SetImage["payload"], "image">;
export type ImageOptions = Omit<KeyOf<SetImage, "payload">, "image">;

/**
* Options that define how to render a title associated with an action.
*/
export type TitleOptions = Omit<SetTitle["payload"], "title">;
export type TitleOptions = Omit<KeyOf<SetTitle, "payload">, "title">;

/**
* Options that define the trigger descriptions associated with an action.
*/
export type TriggerDescriptionOptions = SetTriggerDescription["payload"];
export type TriggerDescriptionOptions = KeyOf<SetTriggerDescription, "payload">;

0 comments on commit dd2f9e5

Please sign in to comment.