Skip to content

Missing TypeScript response type for files.uploadV2 #2459

@osmanpontes

Description

@osmanpontes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions