Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Missing TypeScript response type for files.uploadV2

未关闭 适合新手
#2,459 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@dajiaohuang 已经在做这个了。

开始于 2026年9月25日。

  • #2751 来自 @dajiaohuang —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
typescript
领域
api

调研方向

从 methods.d.ts 开始,将 files.uploadV2 声明与现有的 files.upload 和 FilesUploadResponse 类型进行比较。定义并关联 issue 中描述的具体响应结构,然后验证在不使用 workaround 的情况下,访问 result.files 和嵌套文件 id 可以通过类型检查。

由索引模型根据 Issue 内容生成。

描述

area:typescript auto-triage-skip bug pkg:web-api

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.

主要语言
TypeScript
星标
3.4k
派生
691
平均合并
1 天 2 小时
30 天内合并 PR
19

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

slackapi/node-slack-sdk 的其他 Issue

查看 slackapi/node-slack-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。