Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve type for upload file v2 #1848

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/web-api/src/types/request/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface FileUploadBinaryContents {
// File upload contents can be provided using either `content` or `file` arguments - and one of these is required.
type FileUploadContents = FileUploadStringContents | FileUploadBinaryContents;

type FileUpload = FileUploadContents & FileDestinationArgumentChannels & FileType & {
type FileUpload = FileUploadContents & (FileDestinationArgumentChannels | FileDestinationArgument) & FileType & {
/** @description Name of the file. */
filename?: string;
/** @description The message text introducing the file in specified channel(s). */
Expand All @@ -144,6 +144,8 @@ export type FileUploadV2 = FileUpload & {
alt_text?: string;
/** @description Channel ID where the file will be shared. If not specified the file will be private. */
channel_id?: string;
/** @deprecated use channel_id instead */
Copy link
Contributor Author

@WilliamBergamin WilliamBergamin Jul 18, 2024

Choose a reason for hiding this comment

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

Not sure if we could do anything else then deprecate this 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Nailed it!

channels?: string;
/** @description Syntax type of the snippet being uploaded. E.g. `python`. */
snippet_type?: string;
};
Expand Down
9 changes: 9 additions & 0 deletions packages/web-api/test/types/methods/files.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,20 @@ expectAssignable<Parameters<typeof web.files.uploadV2>>([{
channels: 'C1234', // optionally share to one or more channels
content: 'text',
}]);
expectAssignable<Parameters<typeof web.files.uploadV2>>([{
channel_id: 'C1234', // optionally share to one or more channels
content: 'text',
}]);
expectAssignable<Parameters<typeof web.files.uploadV2>>([{
channels: 'C1234',
thread_ts: '12345.67', // or even to a specific thread
content: 'text',
}]);
expectAssignable<Parameters<typeof web.files.uploadV2>>([{
channel_id: 'C1234',
thread_ts: '12345.67', // or even to a specific thread
content: 'text',
}]);

// files.comments.delete
// -- sad path
Expand Down
Loading