Skip to content

feat: add .d.ts for @tarojs/extend (based on @types/zepto) #17796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

holyfata
Copy link

@holyfata holyfata commented Jun 4, 2025

这个 PR 做了什么? (简要描述所做更改)
修复@tarojs/extend缺乏类型声明

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • [*] 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)
  • 鸿蒙(harmony)

Summary by CodeRabbit

  • 新功能
    • 为 Zepto 库引入了完整的 TypeScript 类型声明,提升了类型安全和智能提示体验。
    • 现在在 TypeScript 项目中使用 Zepto 时可获得完善的接口和方法类型支持。

Copy link

coderabbitai bot commented Jun 4, 2025

Walkthrough

本次变更为 @tarojs/extend 包新增了完整的 TypeScript 声明文件,并在 package.json 中配置了 types 字段及相关文件目录,以确保类型声明能被正确分发和识别。未涉及其他功能或代码的修改。

Changes

文件/文件组 变更摘要
packages/taro-extend/package.json 增加 "types" 字段指向 "types/index.d.ts",并将 "types" 目录加入 "files" 数组
packages/taro-extend/types/index.d.ts 新增 Zepto 相关完整 TypeScript 类型声明文件

Sequence Diagram(s)

sequenceDiagram
    participant TSUser as TypeScript 用户
    participant TaroExtend as @tarojs/extend
    participant Types as types/index.d.ts

    TSUser->>TaroExtend: import '@tarojs/extend'
    TaroExtend-->>Types: 查找 types/index.d.ts
    Types-->>TSUser: 提供 Zepto API 类型声明
Loading

Assessment against linked issues

Objective Addressed Explanation
为 @tarojs/extend 包提供 TypeScript 声明文件,解决“Could not find a declaration file for module @tarojs/extend”报错 (#17795)

Assessment against linked issues: Out-of-scope changes

(未发现超出已关联 issue 目标范围的代码变更)

Poem

兔子敲键,类型声明添,
Zepto API,类型齐全。
TS 再无错,导入不再烦,
代码如春风,开发乐无边。
(づ。◕‿‿◕。)づ

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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 (2)
packages/taro-extend/src/index.d.ts (2)

26-27: 建议添加 export as namespace 支持全局 UMD 调用
如果需要在非模块环境下通过全局变量访问 Zepto,建议在声明文件开头加入:

export as namespace Zepto;

1665-1666: 建议在导出语句结尾添加分号
为保持一致的代码风格,export { $ } 后添加 ;

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7185605 and d7ea925.

📒 Files selected for processing (2)
  • packages/taro-extend/package.json (1 hunks)
  • packages/taro-extend/src/index.d.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/taro-extend/src/index.d.ts

[error] 208-208: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 210-211: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

🔇 Additional comments (3)
packages/taro-extend/src/index.d.ts (2)

1-25: 许可证头部校验
MIT 许可证及原作者信息齐全,无需进一步更改。


1663-1666: 校验类型导出与实际模块导出是否一致
声明使用 export { $ } 导出命名符号,请确认 src/index.js 的导出方式是否匹配,否则可能导致类型定义与运行时代码不一致。

packages/taro-extend/package.json (1)

8-8: 确认 types 字段指向正确路径
已新增 "types": "src/index.d.ts",请验证打包产物中包含该文件并且路径无误。

@holyfata holyfata requested a review from Single-Dancer June 6, 2025 08:47
Copy link

@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: 2

🧹 Nitpick comments (1)
packages/taro-extend/types/index.d.ts (1)

1265-1296: 考虑移除已弃用的方法

类型定义中包含了多个标记为 @deprecated 的方法(如 binddelegatedieliveunbindundelegate)。如果 @tarojs/extend 是一个现代化的实现,可以考虑不包含这些已弃用的 API,以鼓励使用推荐的 on/off 方法。

Also applies to: 1398-1414

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7ea925 and 80f1d52.

📒 Files selected for processing (2)
  • packages/taro-extend/package.json (1 hunks)
  • packages/taro-extend/types/index.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro-extend/package.json
🧰 Additional context used
🪛 Biome (1.9.4)
packages/taro-extend/types/index.d.ts

[error] 208-208: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 210-211: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

🔇 Additional comments (2)
packages/taro-extend/types/index.d.ts (2)

1662-1665: 导出策略正确

正确地声明了全局变量 Zepto$,并且模块只导出 $,这符合 jQuery/Zepto 风格库的惯例。


27-1665:

✅ Verification successful

验证类型定义与实际实现的一致性

这个文件似乎是 Zepto 类型定义的完整副本。需要确认 @tarojs/extend 是否真的实现了所有这些 API。如果 @tarojs/extend 只是 Zepto 的一个子集,应该只包含实际导出的接口。


🏁 Script executed:

#!/bin/bash
# 验证 @tarojs/extend 的实际导出内容
echo "=== 查找 @tarojs/extend 的入口文件 ==="
fd -e js -e ts "index" packages/taro-extend --exclude types | xargs cat 2>/dev/null | head -50

echo -e "\n=== 查看 package.json 了解包的用途 ==="
cat packages/taro-extend/package.json | jq '.description, .main, .exports' 2>/dev/null || cat packages/taro-extend/package.json

Length of output: 401


确认类型定义与实现一致:Zepto 全量导出

根据 packages/taro-extend/src/index.js 中的

export { Zepto as $ } from './jquery/zepto'

该包直接重导出了完整的 Zepto 库,因此在 packages/taro-extend/types/index.d.ts 中提供全量的 Zepto 类型定义是合理且必要的,无需删减或精简。

🧰 Tools
🪛 Biome (1.9.4)

[error] 208-208: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 210-211: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

Comment on lines +206 to +211
* Get a function that ensures that the value of this in the original function refers to the context object. In the second form, the original function is read from the specific property of the context object.
*/
proxy(fn: Function, context: any): Function;

/**
* Ajax
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

避免使用 Function 类型

静态分析工具正确地指出了这里使用 Function 类型过于宽泛。建议使用更具体的函数签名。

-    proxy(fn: Function, context: any): Function;
+    proxy(fn: (...args: any[]) => any, context: any): (...args: any[]) => any;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* Get a function that ensures that the value of this in the original function refers to the context object. In the second form, the original function is read from the specific property of the context object.
*/
proxy(fn: Function, context: any): Function;
/**
* Ajax
/**
* Get a function that ensures that the value of this in the original function refers to the context object. In the second form, the original function is read from the specific property of the context object.
*/
proxy(fn: (...args: any[]) => any, context: any): (...args: any[]) => any;
/**
* Ajax
*/
🧰 Tools
🪛 Biome (1.9.4)

[error] 208-208: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 210-211: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

🤖 Prompt for AI Agents
In packages/taro-extend/types/index.d.ts around lines 206 to 211, the use of the
broad `Function` type for the `fn` parameter and return type in the `proxy`
method should be replaced with a more specific function signature. Update the
type annotations to define the expected input parameters and return type
explicitly, improving type safety and clarity.

Comment on lines +1 to +26
/*
zepto-1.0rc1.d.ts may be freely distributed under the MIT license.

Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/zepto.d.ts

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

验证许可证和版权信息的适用性

这个文件头保留了原始 zepto.d.ts 的 MIT 许可证和 2013 年的版权信息。建议确认:

  1. 是否需要添加 Taro 项目的版权信息
  2. 是否需要说明这是基于 @types/zepto 的衍生作品

🏁 Script executed:

#!/bin/bash
# 检查 @tarojs/extend 包的实际实现和许可证信息
echo "=== 检查 @tarojs/extend 的实现文件 ==="
fd -e js -e ts . packages/taro-extend --exclude types | head -20

echo -e "\n=== 检查项目的许可证文件 ==="
cat LICENSE 2>/dev/null || cat LICENSE.md 2>/dev/null || echo "未找到许可证文件"

echo -e "\n=== 检查其他包的类型声明文件头 ==="
fd -e d.ts . packages --exclude taro-extend | xargs grep -l "Copyright" | head -5 | xargs head -10

Length of output: 7521


在 types/index.d.ts 顶部补充 Taro 项目版权及许可证声明

为保证对 Zepto 原始 d.ts 的 MIT 许可证合规性,同时声明本库的版权与许可证,建议在 packages/taro-extend/types/index.d.ts 顶部新增项目头部注释,并保留原有 Zepto 许可证。示例如下:

+/*
+ * Taro Extend
+ * Copyright (c) 2018 O2Team
+ * Licensed under the MIT License. See LICENSE in project root for details.
+ */
 /*
 zepto-1.0rc1.d.ts may be freely distributed under the MIT license.
 
 Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/zepto.d.ts
 ...
*/
  • 保留 Zepto d.ts 中的所有原始版权和许可证文本
  • 在其上方或之后添加本项目 (@tarojs/extend) 的 MIT 版权声明
  • 如有需要,可在注释中说明该声明文件基于 @types/zepto 衍生
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/*
zepto-1.0rc1.d.ts may be freely distributed under the MIT license.
Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/zepto.d.ts
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Taro Extend
* Copyright (c) 2018 O2Team
* Licensed under the MIT License. See LICENSE in project root for details.
*/
/*
zepto-1.0rc1.d.ts may be freely distributed under the MIT license.
Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/zepto.d.ts
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
🤖 Prompt for AI Agents
In packages/taro-extend/types/index.d.ts at lines 1 to 26, the file currently
only contains the original Zepto d.ts MIT license and copyright from 2013. To
comply with licensing and clarify ownership, add a new header comment at the top
of this file that includes the @tarojs/extend project's MIT copyright and
license statement. Keep the existing Zepto license intact below it, and
optionally include a note that this declaration file is derived from
@types/zepto. This ensures proper attribution and clear licensing for the
combined work.

This was referenced Jun 7, 2025
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.

[Bug]: Could not find a declaration file for module @tarojs/extend
3 participants