Skip to content

Commit

Permalink
fix: types for AttachmentContextValue (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 9, 2024
1 parent 6d619b1 commit 2a4be26
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/react/src/context/react/AttachmentContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,33 @@ import {
} from "../stores/Attachment";

export type AttachmentContextValue = {
type: "composer" | "message";
useAttachment: ReadonlyStore<
ComposerAttachmentState | MessageAttachmentState
>;
} & (
| {
type: "composer";
useAttachment: ReadonlyStore<ComposerAttachmentState>;
}
| {
type: "message";
useAttachment: ReadonlyStore<MessageAttachmentState>;
}
);
};

type ComposerAttachmentContextValue = {
type: "composer";
useAttachment: ReadonlyStore<ComposerAttachmentState>;
};

type MessageAttachmentContextValue = {
type: "message";
useAttachment: ReadonlyStore<MessageAttachmentState>;
};

export const AttachmentContext = createContext<AttachmentContextValue | null>(
null,
);

export function useAttachmentContext(): AttachmentContextValue;
export function useAttachmentContext<
TType extends AttachmentContextValue["type"],
>(options: { type: TType }): AttachmentContextValue & { type: TType };
export function useAttachmentContext(options: {
type: "composer";
}): ComposerAttachmentContextValue;
export function useAttachmentContext(options: {
type: "message";
}): MessageAttachmentContextValue;
export function useAttachmentContext(options: {
optional: true;
}): AttachmentContextValue | null;
Expand Down

0 comments on commit 2a4be26

Please sign in to comment.