slackapi / slackapi/node-slack-sdk

Missing TypeScript response type for files.uploadV2

Open Beginner friendly
#2,459 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:typescript auto-triage-skip bug pkg:web-api
Dominant language
TypeScript
Stars
3.4k
Forks
688
Avg merge
15h 31m
Merged PRs (30d)
27

Description

Description

The files.uploadV2 method returns WebAPICallResult instead of a specific response type like other file methods have. This causes TypeScript errors when accessing the files property from the response.

Current behavior

// In methods.d.ts
uploadV2: MethodWithRequiredArgument<FilesUploadV2Arguments, WebAPICallResult>;

// Usage causes TS error
const result = await client.files.uploadV2({ file: buffer, filename });
const fileId = result.files[0].files[0].id;
// Error: Property 'files' does not exist on type 'WebAPICallResult'. (ts 2339)

Expected behavior

A specific response type should be defined, similar to other methods:

// Expected in methods.d.ts
uploadV2: MethodWithRequiredArgument<FilesUploadV2Arguments, FilesUploadV2Response>;

Actual API response structure

The actual response from files.uploadV2 has this structure:

{
  "ok": true,
  "files": [
    {
      "ok": true,
      "files": [
        {
          "id": "F0A68QU0H08",
          "created": 1766578264,
          "timestamp": 1766578264,
          "name": "filename.jpg",
          "title": "filename.jpg",
          "mimetype": "",
          "filetype": "",
          "user": "U0A57PBUCR1",
          "size": 266967,
          "mode": "hosted",
          "is_external": false,
          "is_public": false,
          "url_private": "https://files.slack.com/...",
          "url_private_download": "https://files.slack.com/.../download/...",
          "permalink": "https://....slack.com/files/...",
          "permalink_public": "https://slack-files.com/...",
          "file_access": "visible"
        }
      ],
      "response_metadata": {
        "scopes": ["files:write", "..."],
        "acceptedScopes": ["files:write"]
      }
    }
  ]
}

Suggested type definition

export interface FilesUploadV2Response extends WebAPICallResult {
  files: Array<{
    ok: boolean;
    files: Array<{
      id: string;
      created: number;
      timestamp: number;
      name: string;
      title: string;
      mimetype: string;
      filetype: string;
      user: string;
      user_team: string;
      size: number;
      mode: string;
      is_external: boolean;
      is_public: boolean;
      url_private: string;
      url_private_download: string;
      permalink: string;
      permalink_public: string;
      file_access: string;
      // ... other optional fields
    }>;
    response_metadata?: {
      scopes: string[];
      acceptedScopes: string[];
    };
  }>;
}

Workaround

Currently using inline type cast:

const result =
  /** @type {{ ok: boolean, files: Array<{ ok: boolean, files: Array<{ id: string }> }> }} */
  (await client.files.uploadV2({ file: buffer, filename }));

Environment

  • @slack/web-api version: 7.13.0
  • Node.js version: 22.x
  • TypeScript version: 5.x (via tsserver/JSDoc)

Related

The deprecated files.upload method has proper typing with FilesUploadResponse, but its replacement uploadV2 uses the generic WebAPICallResult.

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • @slack/socket-mode
  • @slack/types
  • I don't know
Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in methods.d.ts by comparing the files.uploadV2 declaration with the existing files.upload and FilesUploadResponse typing. Define and connect the specific response shape described in the issue, then verify that accessing result.files and nested file ids type-checks without the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.