Skip to content

Instantly share code, notes, and snippets.

@yuya-maemichi-synspective
Last active November 22, 2023 06:47
Show Gist options
  • Save yuya-maemichi-synspective/7215fd161e1898051f0423f3f18ed651 to your computer and use it in GitHub Desktop.
Save yuya-maemichi-synspective/7215fd161e1898051f0423f3f18ed651 to your computer and use it in GitHub Desktop.
Slack SDK has a loose typing
// https://github.com/slackapi/node-slack-sdk/blob/1312f6222497ca58af6788ea32744d7fd85964ce/packages/web-api/src/methods.ts#L1975-L1984
type Buffer = object;
type Stream = object;
type FileUpload = (
| {
channels?: string; // comma-separated list of channels
}
| {
channels: string; // comma-separated list of channels
thread_ts: string; // if specified, `channels` must be set
}
) &
(
| {
content: string; // if omitted, must provide `file`
}
| {
file: Buffer | Stream | string; // if omitted, must provide `content`
}
) &
Partial<{
filename: string;
filetype: string;
initial_comment: string;
title: string;
}>;
const u0: FileUpload = {
content: "this is a content.",
};
const u1: FileUpload = {
channels: "foo,bar",
content: "this is a content.",
};
// @ts-expect-error no channels, but no error
const u2: FileUpload = {
thread_ts: "foo",
content: "this is a content.",
};
// @ts-expect-error no content nor file
const u3: FileUpload = {
};
const u4: FileUpload = {
file: "this is a content.",
};
const u5: FileUpload = {
file: "this is a content.",
filename: "content.txt",
filetype: "txt",
title: "content",
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment