Skip to content

Conversation

@DimplesY
Copy link
Contributor

@DimplesY DimplesY commented Sep 5, 2025

变更内容

本次 PR 优化了容器检查逻辑,主要变更包括:

  1. 使用可选链操作符(?.)替代显式的 null 检查
  2. 使用 instanceof HTMLElement 进行类型检查替代 @ts-expect-error
  3. 使用 classList.contains() 替代直接访问 className
  4. 提取 firstChild 变量提高代码可读性

变更原因

  • 原代码使用 @ts-expect-error 绕过类型检查,存在潜在风险
  • 直接访问 className 不够健壮,无法处理多个类名的情况
  • 新实现更符合现代 JavaScript/TypeScript 最佳实践

影响范围

此变更仅影响初始化时的容器检查逻辑,不会改变功能行为,但提高了代码的:

  • 类型安全性 (TypeScript 兼容性)
  • 运行时健壮性
  • 可维护性

测试建议

  1. 验证容器为空时的初始化
  2. 验证容器包含 maptalks-wrapper 类时的错误抛出
  3. 验证容器包含其他内容时的正常初始化

@fuzhenn fuzhenn merged commit 9eb056a into maptalks:master Sep 8, 2025
3 checks passed
@fuzhenn
Copy link
Member

fuzhenn commented Sep 8, 2025

非常感谢!

@DimplesY DimplesY deleted the patch-1 branch September 17, 2025 03:12
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.

2 participants