Skip to content

fix(types): 补充 setStorage 支付宝平台返回类型定义#19248

Open
Jarvis636431 wants to merge 6 commits into
NervJS:mainfrom
Jarvis636431:fix/setstorage-alipay-typings
Open

fix(types): 补充 setStorage 支付宝平台返回类型定义#19248
Jarvis636431 wants to merge 6 commits into
NervJS:mainfrom
Jarvis636431:fix/setstorage-alipay-typings

Conversation

@Jarvis636431
Copy link
Copy Markdown

@Jarvis636431 Jarvis636431 commented May 21, 2026

Summary

  • Taro.setStorage 的类型定义仅包含 errMsg 字段,但支付宝小程序下实际返回 { success: true }
  • 新增 setStorage.SuccessCallbackResult 接口,扩展 success? 字段并标记为 @supported alipay

Changes

  • packages/taro/types/api/storage/index.d.ts
    • 新增 setStorage.SuccessCallbackResult extends TaroGeneral.CallbackResult
    • Option.success 回调参数类型更新
    • setStorage() 返回值更新为 Promise<setStorage.SuccessCallbackResult>

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

发行说明

  • 文档

    • 新增可参考的环境配置示例与填写说明,方便项目初始化和多环境配置
  • 改进

    • 更新模板生成逻辑以确保环境示例随新项目创建
    • 调整忽略规则,忽略实际环境文件但保留示例文件
    • 优化存储 API 的类型定义,提升开发时提示准确性

Review Change Stack

Jarvis636431 and others added 4 commits February 13, 2026 11:28
支付宝小程序下 setStorage 返回 `{ success: true }`,补充对应的
SuccessCallbackResult 类型定义,标记为 @supported alipay。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4b80a623-7efd-44ad-93d1-b378d6b40f8e

📥 Commits

Reviewing files that changed from the base of the PR and between 28da52b and 6f6b08d.

📒 Files selected for processing (1)
  • packages/taro/types/api/storage/index.d.ts

Walkthrough

新增 CLI 模板的 .env.example 示例并在模板生成器中注册,同时更新 .gitignore;调整 setStorage 的 TypeScript 类型,引入 SuccessCallbackResult 并将相关回调与返回值类型改为该类型,以包含可选的 success?: boolean 字段。

变更

环境配置模板集成

Layer / File(s) Summary
环境模板文件与生成器集成
packages/taro-cli/templates/default/_env.example, packages/taro-cli/templates/default/_gitignore, packages/taro-cli/templates/default/template_creator.js
添加 .env.example 模板文件,包含配置文档参考和 TARO_APP_ID 占位示例;更新 .gitignore 规则忽略 .env* 但保留 .env.example;在 template_creator.jshandler 中注册 /_env.example 映射以支持模板复制。

存储 API 类型定义适配

Layer / File(s) Summary
setStorage 返回值类型精化
packages/taro/types/api/storage/index.d.ts
新增 setStorage.SuccessCallbackResult 类型,并将 setStorage.Option.successcomplete 回调参数以及 TaroStatic.setStorage 的 Promise 返回类型由 TaroGeneral.CallbackResult 改为 SuccessCallbackResult;在该类型中新增可选字段 errMsg?: stringsuccess?: booleansuccess 标注 @supported alipay)。

代码审核工作量

🎯 2 (Simple) | ⏱️ ~10 分钟

🐰 新模板在林间闪,
忽略规则轻放行。
存储类型细又稳,
支付宝返值有声,
小改动里见晴空。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning 包含三个超出issue范围的文件改动:_env.example、_gitignore和template_creator.js,这些环境配置模板变更与setStorage类型定义问题无关。 将环境配置模板文件(_env.example、_gitignore、template_creator.js)移至单独PR,保持该PR专注于setStorage类型定义的修复。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确反映了主要变更——为setStorage补充支付宝平台的返回类型定义,与所有文件改动直接相关。
Linked Issues check ✅ Passed 代码更改完全满足issue #19192的核心需求:新增setStorage.SuccessCallbackResult接口,添加支付宝特定的success字段,更新Promise返回类型和回调参数类型。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: dependency version conflict. Check your lock file or package.json.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/taro-cli/templates/default/_env.example (1)

1-3: 💤 Low value

考虑补充更多常用环境变量示例。

当前模板仅包含 TARO_APP_ID 一个示例。可以考虑添加更多 Taro 项目中常用的环境变量(如 API 基础 URL、调试开关等),帮助用户更快理解环境配置的用途。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/taro-cli/templates/default/_env.example` around lines 1 - 3, The
template only shows TARO_APP_ID; add several common example environment
variables with short inline descriptions so users understand usage: include
variables like API_BASE_URL (backend base URL), NODE_ENV
(development|production), DEBUG or LOG_LEVEL (toggle verbose logs),
FEATURE_FLAGS or FEATURE_<NAME> (feature toggles), ANALYTICS_KEY or SENTRY_DSN
(monitoring), and optional MOCK_API=true/false; update the _env.example near the
TARO_APP_ID entry to list these keys with placeholder values and brief comments
explaining each one.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/taro/types/api/storage/index.d.ts`:
- Around line 30-35: The current SuccessCallbackResult extends
TaroGeneral.CallbackResult which forces errMsg to be required; change
SuccessCallbackResult to remove the required errMsg from the base and
reintroduce it as optional (e.g. use Omit<TaroGeneral.CallbackResult, "errMsg">
then add errMsg?: string and success?: boolean) so the Alipay setStorage success
callback type no longer requires errMsg; update the declaration named
SuccessCallbackResult accordingly.

---

Nitpick comments:
In `@packages/taro-cli/templates/default/_env.example`:
- Around line 1-3: The template only shows TARO_APP_ID; add several common
example environment variables with short inline descriptions so users understand
usage: include variables like API_BASE_URL (backend base URL), NODE_ENV
(development|production), DEBUG or LOG_LEVEL (toggle verbose logs),
FEATURE_FLAGS or FEATURE_<NAME> (feature toggles), ANALYTICS_KEY or SENTRY_DSN
(monitoring), and optional MOCK_API=true/false; update the _env.example near the
TARO_APP_ID entry to list these keys with placeholder values and brief comments
explaining each one.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2124656d-b993-4961-8eea-ffe63390e2e5

📥 Commits

Reviewing files that changed from the base of the PR and between 9c6c511 and 28da52b.

📒 Files selected for processing (4)
  • packages/taro-cli/templates/default/_env.example
  • packages/taro-cli/templates/default/_gitignore
  • packages/taro-cli/templates/default/template_creator.js
  • packages/taro/types/api/storage/index.d.ts

Comment thread packages/taro/types/api/storage/index.d.ts Outdated
This was referenced May 23, 2026
@felix9ia
Copy link
Copy Markdown
Contributor

不只是 Taro.setStorage 这一个方法,其他的使用 TaroGeneral.CallbackResult 的接口也存在这样的问题吧

@Jarvis636431
Copy link
Copy Markdown
Author

不只是 Taro.setStorage 这一个方法,其他的使用 TaroGeneral.CallbackResult 的接口也存在这样的问题吧

确实,这个问题不只存在于 Taro.setStorage。根因是 TaroGeneral.CallbackResulterrMsg 定义成必填字段,而部分支付宝 API 成功返回值可能只有 success,不一定包含 errMsg

我看了一下,目前 packages/taro/types/api 里有大量接口直接使用 TaroGeneral.CallbackResult 作为 success / complete / Promise 返回值。单独给 setStorage 增加 SuccessCallbackResult 只能解决 issue 中暴露的一个点,不能系统性解决同类问题。

我倾向于后续改成一个通用类型,例如为支付宝这类结果新增 OptionalErrMsgCallbackResult / AlipayCallbackResult,再逐个把确认过支付宝返回 { success } 的接口迁过去,避免直接把全局 CallbackResult.errMsg 改成可选导致微信等平台类型被放宽。

@felix9ia
Copy link
Copy Markdown
Contributor

不只是 Taro.setStorage 这一个方法,其他的使用 TaroGeneral.CallbackResult 的接口也存在这样的问题吧

确实,这个问题不只存在于 Taro.setStorage。根因是 TaroGeneral.CallbackResulterrMsg 定义成必填字段,而部分支付宝 API 成功返回值可能只有 success,不一定包含 errMsg

我看了一下,目前 packages/taro/types/api 里有大量接口直接使用 TaroGeneral.CallbackResult 作为 success / complete / Promise 返回值。单独给 setStorage 增加 SuccessCallbackResult 只能解决 issue 中暴露的一个点,不能系统性解决同类问题。

我倾向于后续改成一个通用类型,例如为支付宝这类结果新增 OptionalErrMsgCallbackResult / AlipayCallbackResult,再逐个把确认过支付宝返回 { success } 的接口迁过去,避免直接把全局 CallbackResult.errMsg 改成可选导致微信等平台类型被放宽。

@Jarvis636431 其实新增返回类然后用 | 来表达其实还是不合适,那用 Taro 的开发者再去手动适配这个success 吗?
适配这件事 Taro 并没有做好,现在已经跟微信生态高度耦合了

隔壁的 Uni 对于跨平台适配的理解我觉得是对的。框架内部去消化不同平台出入参的差异性,然后跨端平台提供出来的接口,都是跨端平台自己定义的出入参数据格式。比如我在 #19216 提到的 uni.requestPayment,再比如uni.getLocation

Taro 如果不尽早修正,沉没成本会越来越高....我现在都有点不想用 Taro 了,因为 Taro 根本就没有做到跨端适配

@Jarvis636431
Copy link
Copy Markdown
Author

不只是 Taro.setStorage 这一个方法,其他的使用 TaroGeneral.CallbackResult 的接口也存在这样的问题吧

确实,这个问题不只存在于 Taro.setStorage。根因是 TaroGeneral.CallbackResulterrMsg 定义成必填字段,而部分支付宝 API 成功返回值可能只有 success,不一定包含 errMsg
我看了一下,目前 packages/taro/types/api 里有大量接口直接使用 TaroGeneral.CallbackResult 作为 success / complete / Promise 返回值。单独给 setStorage 增加 SuccessCallbackResult 只能解决 issue 中暴露的一个点,不能系统性解决同类问题。
我倾向于后续改成一个通用类型,例如为支付宝这类结果新增 OptionalErrMsgCallbackResult / AlipayCallbackResult,再逐个把确认过支付宝返回 { success } 的接口迁过去,避免直接把全局 CallbackResult.errMsg 改成可选导致微信等平台类型被放宽。

@Jarvis636431 其实新增返回类然后用 | 来表达其实还是不合适,那用 Taro 的开发者再去手动适配这个success 吗? 适配这件事 Taro 并没有做好,现在已经跟微信生态高度耦合了

隔壁的 Uni 对于跨平台适配的理解我觉得是对的。框架内部去消化不同平台出入参的差异性,然后跨端平台提供出来的接口,都是跨端平台自己定义的出入参数据格式。比如我在 #19216 提到的 uni.requestPayment,再比如uni.getLocation

Taro 如果不尽早修正,沉没成本会越来越高....我现在都有点不想用 Taro 了,因为 Taro 根本就没有做到跨端适配

哎,是的,现在已经是高度绑定微信生态,对于其他平台的适配只是额外增加 api 并不合适,框架本身应该是简化开发者负担的,同样的行为需要同样的 api 定义,而不是一个平台新增一个 api,除非做好语义化

This was referenced May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Taro.setStorage 返回值ts 定义未适配支付宝

2 participants