Skip to content

Commit

Permalink
fix: improve type for upload file v2 (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamBergamin authored Jul 18, 2024
1 parent 178223c commit a055e66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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 */
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

0 comments on commit a055e66

Please sign in to comment.