-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
base: main
Are you sure you want to change the base?
feat: add .d.ts for @tarojs/extend (based on @types/zepto) #17796
Conversation
Walkthrough本次变更为 Changes
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 类型声明
Assessment against linked issues
Assessment against linked issues: Out-of-scope changes(未发现超出已关联 issue 目标范围的代码变更) Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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"
,请验证打包产物中包含该文件并且路径无误。
There was a problem hiding this 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
的方法(如bind
、delegate
、die
、live
、unbind
、undelegate
)。如果 @tarojs/extend 是一个现代化的实现,可以考虑不包含这些已弃用的 API,以鼓励使用推荐的on
/off
方法。Also applies to: 1398-1414
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.jsonLength 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)
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免使用 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.
* 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.
/* | ||
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. | ||
*/ | ||
|
There was a problem hiding this comment.
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 年的版权信息。建议确认:
- 是否需要添加 Taro 项目的版权信息
- 是否需要说明这是基于 @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.
/* | |
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.
这个 PR 做了什么? (简要描述所做更改)
修复@tarojs/extend缺乏类型声明
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit