@deveco-test/deveco-code 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/package.json +6 -5
  3. package/resources/deveco/skills/customize-deveco/.deveco-builtin +1 -0
  4. package/resources/deveco/skills/customize-deveco/SKILL.md +469 -0
  5. package/resources/deveco/skills/deveco-cli/.deveco-builtin +1 -0
  6. package/resources/deveco/skills/deveco-cli/SKILL.md +240 -0
  7. package/resources/deveco/skills/hmos-arkui-develop-skill/.deveco-builtin +1 -0
  8. package/resources/deveco/skills/hmos-arkui-develop-skill/SKILL.md +83 -0
  9. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/01-layout.md +629 -0
  10. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/02-basic-components.md +645 -0
  11. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/03-data-display.md +81 -0
  12. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/04-selectors.md +76 -0
  13. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/05-media.md +60 -0
  14. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/06-advanced.md +32 -0
  15. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/07-security.md +30 -0
  16. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/08-state-decorators.md +79 -0
  17. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/09-animation.md +111 -0
  18. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/10-gesture.md +59 -0
  19. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/11-dialog-menu.md +92 -0
  20. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/12-navigation.md +81 -0
  21. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/13-rendering.md +22 -0
  22. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/14-extension.md +22 -0
  23. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/15-theme-style.md +10 -0
  24. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/16-enums.md +87 -0
  25. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/17-resources.md +1379 -0
  26. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/18-error-code.md +24 -0
  27. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/_index.md +75 -0
  28. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/00-arkts-syntax.md +229 -0
  29. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/01-import.md +116 -0
  30. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/02-uicontext.md +56 -0
  31. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/03-component.md +105 -0
  32. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/04-build.md +41 -0
  33. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/05-state.md +300 -0
  34. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/06-rendering.md +67 -0
  35. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/07-attribute-params.md +219 -0
  36. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/08-navigation.md +102 -0
  37. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/09-dialog.md +72 -0
  38. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/10-style.md +90 -0
  39. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/11-extension.md +54 -0
  40. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/12-layout.md +69 -0
  41. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/13-performance.md +27 -0
  42. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/14-deprecated.md +28 -0
  43. package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/_index.md +79 -0
  44. package/resources/deveco/skills/hmos-runtime-fix-skill/.deveco-builtin +1 -0
  45. package/resources/deveco/skills/hmos-runtime-fix-skill/SKILL.md +187 -0
  46. package/resources/deveco/skills/hmos-runtime-fix-skill/SKILL_CN.md +160 -0
  47. package/resources/deveco/skills/hmos-runtime-fix-skill/evals/evals.json +17 -0
  48. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/businesserror_patterns.md +17 -0
  49. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/error_patterns.md +31 -0
  50. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/fault-mode-library.md +57 -0
  51. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/outofmemoryerror_patterns.md +19 -0
  52. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/rangeerror_patterns.md +15 -0
  53. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/referenceerror_patterns.md +23 -0
  54. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/syntaxerror_patterns.md +14 -0
  55. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/typeerror_patterns.md +19 -0
  56. package/resources/deveco/skills/hmos-runtime-fix-skill/reference/urierror_patterns.md +17 -0
  57. package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/collect-hilog.mjs +120 -0
  58. package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/jscrash-report.mjs +138 -0
  59. package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/parse-jscrash-log.mjs +126 -0
  60. package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/shared/deveco-cli.mjs +79 -0
  61. package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/shared/jscrash-parse.mjs +389 -0
  62. package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/shared/utils.mjs +27 -0
@@ -0,0 +1,24 @@
1
+ # 18. 错误码速查
2
+
3
+ | 错误码 | 说明 | 相关章节 |
4
+ |--------|------|---------|
5
+ | **100003** | Router 页面栈超过 32 页 | [08-navigation](08-navigation.md) |
6
+ | **100005** | Navigation 跳转未注册 builder 函数的页面 | [08-navigation](08-navigation.md) |
7
+ | **100006** | Navigation 跳转未包含 NavDestination 的页面 | [08-navigation](08-navigation.md) |
8
+ | **100021** | 声明式 FrameNode 不允许修改(设属性、增删子节点、绑定控制器) | [11-extension](11-extension.md) |
9
+ | **10505001** | 成员属性名与 CustomComponent 链式方法/通用属性重名;属性不存在;NavDestination 错用 titleMode 等 | [03-component](03-component.md)、[07-attribute-params](07-attribute-params.md) |
10
+ | **10605038** | 无类型对象字面量(arkts-no-untyped-obj-literals) | [00-arkts-syntax](00-arkts-syntax.md) |
11
+ | **10605040** | 内联对象字面量作类型(arkts-no-obj-literals-as-types) | [00-arkts-syntax](00-arkts-syntax.md) |
12
+ | **106203** | 对未挂载节点执行操作 | [11-extension](11-extension.md) |
13
+ | **10905202** | Button('label') 与 children 同时传入 | [04-build](04-build.md) |
14
+ | **130000** | addMonitor/clearMonitor 目标必须是 @ObservedV2 class 或 @ComponentV2 实例 | [05-state](05-state.md) |
15
+ | **130002** | addMonitor/clearMonitor 回调必须为命名函数 | [05-state](05-state.md) |
16
+ | **140109** | @Builder 内修改入参(API 23+) | [05-state](05-state.md) |
17
+ | **arkts-no-decl-merging** | 跨文件顶层 interface/class 重名 | [03-component](03-component.md) |
18
+ | **arkts-no-destruct-decls** | 禁止解构声明 | [00-arkts-syntax](00-arkts-syntax.md) |
19
+ | **arkts-no-any-unknown** | 禁止 any/unknown | [00-arkts-syntax](00-arkts-syntax.md) |
20
+ | **arkts-no-ctor-prop-decls** | 禁止构造参数属性 | [00-arkts-syntax](00-arkts-syntax.md) |
21
+ | **arkts-no-func-expressions** | 禁止函数表达式(用箭头函数) | [00-arkts-syntax](00-arkts-syntax.md) |
22
+ | **arkts-no-nested-funcs** | @Extend/@Styles 内嵌套函数定义 | [10-style](10-style.md)、[00-arkts-syntax](00-arkts-syntax.md) |
23
+ | **arkts-no-untyped-obj-literals** | 无类型对象字面量 | [00-arkts-syntax](00-arkts-syntax.md) |
24
+ | **arkts-no-spread** | 禁止对象展开 | [00-arkts-syntax](00-arkts-syntax.md) |
@@ -0,0 +1,75 @@
1
+ # ArkUI API 参数速查索引
2
+
3
+ > 各分类独立文件,按需读取。每个组件以"卡片"形式呈现,包含构造签名、参数表、属性方法表和事件表。
4
+
5
+ ## 检索方式(避免整读大文件)
6
+
7
+ **查具体组件 API**(Row / List / Text / Navigation 等):
8
+ - **大文件**(01-layout 24KB / 02-basic 28KB):在「组件索引」查组件所在文件,再 `Grep "^### 组件名" <文件> -A 45 -n` 取卡片(卡片 30–50 行)。**勿整读**,整读只为一张卡片浪费 10×+ token。
9
+ - **小文件**(<5KB,如 03/04/05/07/11/12):直接 Read 整个分类文件即可,比走索引更省。
10
+ - **已知组件所在文件**:直接 `Grep "^### 组件名" <文件> -A 45 -n` 取卡片,可跳过本索引。
11
+
12
+ **查主题 / 枚举 / 资源名**(动画 / 手势 / 装饰器 / 枚举 / sys.symbol):
13
+ - 08/09/10/14/16 文件较小(<5KB),直接 Read 或 Grep 主题词
14
+ - 17-resources(50KB sys.symbol / sys.color 名称表):`Grep "图标名或颜色名" 17-resources.md` 定位,勿整读
15
+
16
+ ## 分类文件
17
+
18
+ | 文件 | 分类 | 大小 |
19
+ |------|------|------|
20
+ | [01-layout.md](01-layout.md) | 1. 布局容器 | 24KB |
21
+ | [02-basic-components.md](02-basic-components.md) | 2. 基础组件 | 28KB |
22
+ | [03-data-display.md](03-data-display.md) | 3. 数据展示组件 | 3KB |
23
+ | [04-selectors.md](04-selectors.md) | 4. 选择器组件 | 2KB |
24
+ | [05-media.md](05-media.md) | 5. 媒体与绘图组件 | 3KB |
25
+ | [06-advanced.md](06-advanced.md) | 6. 高级/组合组件 | 2KB |
26
+ | [07-security.md](07-security.md) | 7. 安全组件 | <1KB |
27
+ | [08-state-decorators.md](08-state-decorators.md) | 8. 状态管理装饰器 | 5KB |
28
+ | [09-animation.md](09-animation.md) | 9. 动画 API | 5KB |
29
+ | [10-gesture.md](10-gesture.md) | 10. 手势与事件 | 3KB |
30
+ | [11-dialog-menu.md](11-dialog-menu.md) | 11. 弹窗/菜单/模态 | 5KB |
31
+ | [12-navigation.md](12-navigation.md) | 12. 导航与路由 | 3KB |
32
+ | [13-rendering.md](13-rendering.md) | 13. 渲染控制 | <1KB |
33
+ | [14-extension.md](14-extension.md) | 14. 自定义扩展 | 1KB |
34
+ | [15-theme-style.md](15-theme-style.md) | 15. 主题与样式 | <1KB |
35
+ | [16-enums.md](16-enums.md) | 16. 枚举类型速查 | 4KB |
36
+ | [17-resources.md](17-resources.md) | 17. 系统资源名称(sys.symbol / sys.color) | 50KB |
37
+
38
+ ## 组件索引(按组件名定位卡片所在文件)
39
+
40
+ > 用 `Grep "^### 组件名" <文件> -A 45 -n` 取卡片。
41
+
42
+ **01-layout.md** — 布局容器
43
+ Row / Column / Flex / Stack / List / ListItem / ListItemGroup / Grid / GridRow / GridCol / WaterFlow / Scroll / Tabs / TabContent / Swiper / RelativeContainer(含核心用法) / SideBarContainer / Panel / Refresh / Badge / Counter / AlphabetIndexer
44
+
45
+ **02-basic-components.md** — 基础组件
46
+ Text / Span / ImageSpan / SymbolSpan·SymbolGlyph / TextInput / TextArea / Button / Image / Slider / Toggle / Radio / Checkbox / CheckboxGroup / Progress / Rating / LoadingProgress / Search / Select
47
+
48
+ **03-data-display.md** — 数据展示
49
+ Gauge / DataPanel / QRCode / CalendarPicker·TextClock·TextTimer
50
+
51
+ **04-selectors.md** — 选择器
52
+ DatePicker / TimePicker / TextPicker / PatternLock
53
+
54
+ **05-media.md** — 媒体与绘图
55
+ Video / Canvas·Shape
56
+
57
+ **07-security.md** — 安全
58
+ SaveButton / PasteButton
59
+
60
+ **11-dialog-menu.md** — 弹窗/菜单/模态
61
+ 弹窗 API / CustomDialogController / 菜单 / Popup / 模态
62
+
63
+ **12-navigation.md** — 导航与路由
64
+ Navigation / NavPathStack / NavDestination / Router
65
+
66
+ ## 主题类文件(按主题词检索,无单组件卡片)
67
+
68
+ | 文件 | 主题 |
69
+ |------|------|
70
+ | 08-state-decorators.md | V1/V2 装饰器、全局状态 API |
71
+ | 09-animation.md | 属性动画 / 动画曲线 / 转场动画 / TransitionEffect / PageTransition / 帧动画 |
72
+ | 10-gesture.md | 基础手势 / 组合手势 / 手势绑定 / 通用事件 / 拖拽事件 |
73
+ | 14-extension.md | Modifier 系列 / 自定义节点 |
74
+ | 16-enums.md | 布局 / 组件 / 手势 / 动画 / 效果 枚举 |
75
+ | 17-resources.md | sys.symbol 各类图标 / sys.color 128 色(Grep 名称定位) |
@@ -0,0 +1,229 @@
1
+ # 0. ArkTS 语法约束(arkts-* 规则)
2
+
3
+ > ArkTS 是 TypeScript 的静态子集,不少 TS 习惯写法在 ArkTS 会编译报错。本节按官方 `arkts-*` 规则标签组织,标签与编译器/linter 报错一一对应。**写任何 .ets 前先扫本文件,尤其 top traps(实测高频)。**
4
+ >
5
+ > 定位:与 01-import 至 20-particle 的 **ArkUI 组件/状态/导航约束** 正交,本节专注 **ArkTS 语言级语法规则**。
6
+
7
+ ## ⚠Top traps(实测高频,生成前必扫)
8
+
9
+ | # | 陷阱 | ❌ 错误 | ✅ 正确 |
10
+ |---|------|---------|--------|
11
+ | 1 | 解构 | `const { a, b } = obj` | `const a = obj.a; const b = obj.b;` |
12
+ | 2 | 无类型对象字面量 | `const cfg = { timeout: 30 }` | `const cfg: Config = { timeout: 30 }`(先声明 `interface Config`) |
13
+ | 3 | 原型/结构类型 | `X.prototype.fn = ...` 或传结构匹配对象 | 在 class 内声明方法;用 `extends`/`implements` 做类型兼容 |
14
+ | 4 | 遗漏 export/import | 一个文件定义 `class CartItem`,另一文件直接用未导出 | 声明处加 `export`;使用处加 `import { CartItem } from '...'` |
15
+ | 5 | kit 命名空间错 | `import { audio } from '@kit.MediaKit'` | `audio` → `@kit.AudioKit`;`media` → `@kit.MediaKit` |
16
+ | 6 | enum 反射方法 | `HeavenlyStem.values()` / `Color.keys()` / `MyEnum.entries()` | ArkTS 枚举无 `.values()/.keys()/.entries()`,声明显式数组迭代 |
17
+
18
+ ### 三个最高频错误的完整正例
19
+
20
+ **① 遗漏 export/import → `Cannot find name 'X'`**(单类最常犯)
21
+
22
+ ```ets
23
+ // ❌ model 文件忘了 export;页面文件忘了 import
24
+ class CartItem { id: string = '' } // CartItem.ets — no export
25
+ struct CartPage { item: CartItem = new CartItem() } // Cannot find name 'CartItem'
26
+
27
+ // ✅ 声明处 export,使用处文件顶部 import
28
+ export class CartItem { id: string = '' } // CartItem.ets
29
+ import { CartItem } from '../model/CartItem' // CartPage.ets — FIRST line
30
+ // 路由表 / @Builder 命名页面 struct 时必须逐个 import——NavPathStack 不会使其全局可见:
31
+ import { HomePage } from './HomePage'
32
+ import { DetailPage } from './DetailPage'
33
+ ```
34
+
35
+ **② 无类型上下文的对象字面量 → `arkts-no-untyped-obj-literals`**(类型不会渗入嵌套字面量或调用实参)
36
+
37
+ ```ets
38
+ // ❌ 无类型上下文,在调用实参/数组元素等任何位置都失败
39
+ const cfg = { timeout: 30 }
40
+ foo({ id: 1, name: 'a' })
41
+ const rows = [{ x: 1 }, { x: 2 }]
42
+
43
+ // ✅ 先声明 interface,在字面量处标注
44
+ interface Config { timeout: number }
45
+ const cfg: Config = { timeout: 30 }
46
+ foo({ id: 1, name: 'a' } as ItemArg) // 标注实参
47
+ const rows: Point[] = [{ x: 1 }, { x: 2 }] // 标注数组而非变量
48
+ // Record 字面量需带引号 key:
49
+ const m: Record<string, number> = { 'a': 1 }
50
+ ```
51
+
52
+ **③ `enum.values()` 或臆造枚举成员 → `Property 'X' does not exist on type 'typeof Enum'`**
53
+
54
+ ```ets
55
+ // ❌ ArkTS 枚举无反射;臆造的框架枚举成员也不存在
56
+ for (const s of HeavenlyStem.values()) {} // .values() 不存在
57
+ animation({ curve: Curve.Spring }) // Curve 无 'Spring'
58
+
59
+ // ✅ 声明显式成员数组迭代;只从 quick-apis/16-enums.md 取真实成员
60
+ const ALL_STEMS: HeavenlyStem[] = [HeavenlyStem.JIA, HeavenlyStem.YI]
61
+ for (const s of ALL_STEMS) {}
62
+ animation({ curve: Curve.Smooth }) // 真实成员
63
+ ```
64
+
65
+ ---
66
+
67
+ ## TypeScript → ArkTS 改写表(tag 与报错一一对应)
68
+
69
+ | TS 写法 | ArkTS 改写 | 规则标签 |
70
+ |---------|-----------|---------|
71
+ | `var x = 1` | `let x = 1` / `const x = 1` | `arkts-no-var` |
72
+ | `let x: any` / `unknown` | 明确类型;未定时用 `Object` 或联合类型 | `arkts-no-any-unknown` |
73
+ | `const { a, b } = obj` | `const a = obj.a; const b = obj.b` | `arkts-no-destruct-decls` |
74
+ | `function f({ a }: P)` | `function f(p: P)` 后用 `p.a` | `arkts-no-destruct-params` |
75
+ | `[x, y] = [y, x]` | 用临时变量逐一赋值 | `arkts-no-destruct-assignment` |
76
+ | `const fn = function() {}` | `const fn = () => {}` | `arkts-no-func-expressions` |
77
+ | `const id = <T>(v: T): T => v` | `function id<T>(v: T): T { return v }` | `arkts-no-generic-lambdas` |
78
+ | 函数体内 `function inner() {}` | `const inner = (): void => {}` 或提升为类方法 | `arkts-no-nested-funcs` |
79
+ | `<string>value` | `value as string` | `arkts-as-casts` |
80
+ | `obj as const` | 显式声明常量类型 | `arkts-no-as-const` |
81
+ | `type T = { x: number }` | `interface T { x: number }` | `arkts-no-obj-literals-as-types` |
82
+ | `f(p: { x: number })` | 定义具名 interface 作参数类型 | `arkts-no-obj-literals-as-types` |
83
+ | `interface I { [key: string]: T }` | `Record<string, T>` | `arkts-no-indexed-signatures` |
84
+ | `type C = A & B` | `interface C extends A, B {}` | `arkts-no-intersection-types` |
85
+ | `type N = T['prop']` | 直接使用目标类型 | `arkts-no-aliases-by-index` |
86
+ | `obj['key']`(非 Record) | `obj.key`;动态 key 用 Record | `arkts-no-props-by-index` |
87
+ | `const o = { a: 1 }`(无类型) | `const o: MyIface = { a: 1 }` 或 Record | `arkts-no-untyped-obj-literals` |
88
+ | `Pick`/`Omit`/`ReturnType` 等 | 手写具名 interface | `arkts-no-utility-types` |
89
+ | `delete obj.x` | 字段加 `\| undefined`,`obj.x = undefined` | `arkts-no-delete` |
90
+ | `'key' in obj` | `obj.key !== undefined` 或 `instanceof` | `arkts-no-in` |
91
+ | `for (const k in obj)` | `for...of` / `Map` / 已知 key 列表 | `arkts-no-for-in` |
92
+ | `v is Cat`(类型守卫) | `instanceof` 检查 + `as` 收窄 | `arkts-no-is` |
93
+ | `{ ...obj1, ...obj2 }` | 构造新对象,显式赋值字段 | `arkts-no-spread` |
94
+ | `throw 'msg'` | `throw new Error('msg')` | `arkts-limited-throw` |
95
+ | `catch (e: Error)` | `catch (e)` 后 `const err = e as Error` | `arkts-no-types-in-catch` |
96
+ | `constructor(public x: number) {}` | 在 class 体内声明字段,构造中赋值 | `arkts-no-ctor-prop-decls` |
97
+ | `#privateField` | `private privateField` | `arkts-no-private-identifiers` |
98
+ | `class D implements Base`(Base 是类) | `extends Base`,或抽 interface | `arkts-implements-only-iface` |
99
+ | `function* gen() { yield }` | 返回数组/迭代器类,或改普通函数 | `arkts-no-generators` |
100
+ | `fn.bind(this)` | 捕获 this 的箭头函数 | `arkts-no-func-bind` |
101
+ | `/pattern/g` | `new RegExp("pattern", "g")` | `arkts-no-regexp-literals` |
102
+ | `Object.assign(t, s)` | 显式赋值字段或用构造器 | `arkts-limited-stdlib` |
103
+ | `obj.hasOwnProperty('k')` | `obj.k !== undefined` | `arkts-limited-stdlib` |
104
+ | `globalThis.x` | 显式导出单例 / AppStorage | `arkts-no-globalthis` |
105
+ | `// @ts-ignore` | 修复底层类型错误;抑制被禁 | `arkts-strict-typing-required` |
106
+ | `import type { T }` | `import { T }` | `arkts-no-special-imports` |
107
+ | `import './polyfill'` | 删除;显式 import 所需符号 | `arkts-no-side-effects-imports` |
108
+ | `import x = require('m')` | `import x from 'm'` | `arkts-no-require` |
109
+ | `export = X` | `export default X` | `arkts-no-export-assignment` |
110
+ | `router.getParams() as MyIface` | interface 不能实例化,用 `as` 转换;构造用 class | TS2693 |
111
+
112
+ ---
113
+
114
+ ## 核心硬约束(未标 WARNING 均为 ERROR 级)
115
+
116
+ ### Types
117
+ | 规则 | 说明 |
118
+ |------|------|
119
+ | 禁止 `any`/`unknown` | 含 `as unknown as T` 双重断言;用具体类型、`Object`、联合类型 |
120
+ | 类型名作用域内唯一 | 不复用 imported 类型名作本地 struct/class 名(`arkts-unique-names`) |
121
+ | 无结构类型 | 需 `extends`/`implements`(`arkts-no-structural-typing`) |
122
+ | 对象字面量需类型上下文 | 含调用实参、回调返回;外层类型不渗入嵌套 |
123
+ | Record 字面量需带引号 key | `{ 'k': v }` 非 `{ k: v }` |
124
+ | 类类型对象字面量列全部字段 | class 默认值不使字段可选;用 `static of()` 工厂 |
125
+ | 无内联对象类型 | 用具名 interface(`arkts-no-obj-literals-as-types`) |
126
+ | 无交叉类型 `A & B` | 用接口继承(`arkts-no-intersection-types`) |
127
+ | 无索引签名 | 用 `Record<K,V>`(`arkts-no-indexed-signatures`) |
128
+ | 工具类型仅 Partial/Required/Readonly/Record | 其余手写(`arkts-no-utility-types`) |
129
+ | 显式标注泛型调用和返回类型 | `arkts-no-inferred-generic-params` / `arkts-no-implicit-return-types` |
130
+ | **enum 无反射方法** | `.values()/.keys()/.entries()` 不存在;用显式成员数组 |
131
+ | **禁止声明合并** | 类/接口分开定义,同类型名不能在多个文件顶层声明(`arkts-no-decl-merging`) |
132
+ | **对象字面量必须补齐全部必填字段** | 字段类型对齐;可选字段才允许缺省,声明时标 `?` |
133
+
134
+ ### Null safety(检查错误最大来源)
135
+ | 规则 | 说明 |
136
+ |------|------|
137
+ | 可能 undefined 的值必须收窄 | `?.`、`?? fallback`、`if (x !== undefined)` |
138
+ | `T \| undefined` 不能赋给 `T` | **含函数实参**:`foo(x)` 中 x 为 `T \| undefined` 不能传给 `param: T`,传参前 `?? defaultValue` 或 if 收窄 |
139
+ | 空状态组件用 `T \| undefined` 或真实初始值 | 不用非空断言 `!` |
140
+ | 优先 `undefined` 而非 `null` | 外部 null 用 `?? undefined` 转换 |
141
+
142
+ ### @Link 绑定约束
143
+ | 规则 | 说明 |
144
+ |------|------|
145
+ | **@Link 源必须是 @State** | 传给子组件 `@Link` 的父属性必须是 `@State`/`@Prop` 等装饰变量,不能是 `private`/普通属性 |
146
+ | **@Link 传值用 `this.`** | `Child({ aLink: this.aState })`(推荐);`$aState` 是 API9 前旧写法,不推荐 |
147
+ | **@Prop 传值** | 见 [05-state](05-state.md) @Prop 节:本地有初始化则可选(同 @State),无则必选;支持父组件常规变量但只做数值初始化、不触发刷新 |
148
+
149
+ ```ets
150
+ // ❌ WRONG — 普通属性传 @Link
151
+ struct Parent {
152
+ private count: number = 0
153
+ build() {
154
+ Child({ count: this.count }) // Error: regular property cannot be assigned to @Link
155
+ }
156
+ }
157
+
158
+ // ✅ RIGHT — @State 才能传 @Link
159
+ struct Parent {
160
+ @State count: number = 0
161
+ build() {
162
+ Child({ count: this.count })
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### Functions and classes
168
+ | 规则 | 说明 |
169
+ |------|------|
170
+ | 不用 `function(){}` 作值 | 用箭头函数(`arkts-no-func-expressions`) |
171
+ | 无嵌套函数声明 | `arkts-no-nested-funcs` |
172
+ | async 方法必须显式标注 `Promise<T>` | 省略报 error;无返回值写 `Promise<void>` |
173
+ | 独立/static 方法无 `this` | static 成员用类名访问(`arkts-no-standalone-this`) |
174
+ | 无构造参数属性 | `arkts-no-ctor-prop-decls` |
175
+ | 同作用域不允许同名函数声明 | 无函数重载,每函数名只有一个实现 |
176
+ | 无 `#` 私有字段 | 用 `private`(`arkts-no-private-identifiers`) |
177
+ | `implements` 仅接口 | 接口不能 extends 类 |
178
+ | 无 generator/`yield`、类表达式、`Function.bind` | |
179
+
180
+ ### Exports and imports("Cannot find name" / "not exported" 高频来源)
181
+ | 规则 | 说明 |
182
+ |------|------|
183
+ | 跨文件使用的类型必须 `export` | 忘记 export 报 `Module '...' declares 'X' locally, but it is not exported` |
184
+ | 自定义类型必须显式 `import` | `Cannot find name 'X'` 几乎总是缺 import |
185
+ | "No overload matches this call" = 实参类型/数量错 | 常见:传错枚举(如 `EdgeEffect.Spring` 处传 `ScrollAlign.Start`)、给类型化枚举传 string、回调签名错 |
186
+
187
+ > kit 归属和速查表见 [01-import](01-import.md)。
188
+
189
+ ### Statements and expressions
190
+ | 规则 | 说明 |
191
+ |------|------|
192
+ | 无任何解构 | 声明/赋值/参数(`arkts-no-destruct-*`) |
193
+ | import 必须在文件顶部 | 其他语句之前(`arkts-no-misplaced-imports`) |
194
+ | 无 `delete`、`in`、`for...in`、`with` | |
195
+ | 非 Record 无索引访问 `obj['k']` | 用点访问(`arkts-no-props-by-index`) |
196
+ | `throw` 只抛 Error+子类 | `catch (e)` 无类型注解;系统 API 错误用 `BusinessError` |
197
+ | 无 `is` 类型守卫 | 用 `instanceof` + `as` |
198
+ | 对象展开受限 | 数组展开 OK(`arkts-no-spread`) |
199
+ | 无正则字面量 | 用 `new RegExp()`(`arkts-no-regexp-literals`) |
200
+ | 无 `@ts-ignore` | `arkts-strict-typing-required` |
201
+ | **JSON.parse 收窄模式** | 先 `as` 转换到原始类型,再逐字段校验赋值到严格类型,不直接使用 `as` 后的对象 |
202
+
203
+ ```ts
204
+ // JSON.parse 收窄 — 不要直接信任 parsed 结果
205
+ interface TaskRaw { id?: number; title?: string }
206
+ const raw = JSON.parse(text) as TaskRaw
207
+ const task: Task = { id: raw.id ?? 0, title: raw.title ?? '' }
208
+ ```
209
+
210
+ ### Standard library
211
+ - 禁用:`eval`、`Object.assign/create/freeze/defineProperty`、`Reflect`/`Proxy`、`Symbol()`(除 `.iterator`)、`globalThis`
212
+ - 无 `import type`、副作用导入、`require`、`export =`
213
+
214
+ ### 模板字符串注意
215
+ > **注意**:`restrictions.md` 声称模板字符串不支持,但 `arkts-rules.md` "Explicitly allowed constructs" 明确 **模板字符串合法**(`Text(\`${this.msg}\`)` 是惯用写法)。以 `arkts-rules.md` 为准——模板字符串、`value as T`、`Record<K,V>`、箭头函数均合法,不要防御性改写。
216
+
217
+ ---
218
+
219
+ ## 显式允许的构造(不要过度限制)
220
+
221
+ 模板字面量、`as T` 断言、`Record<K,V>` + 索引访问、`Partial<T>`/`Required<T>`/`Readonly<T>`、箭头函数、`async/await`、泛型类/接口/函数、数组展开 `[...a]`、表达式上下文 `typeof x`、`new RegExp()`、联合类型/类型别名、`for...of`/`Map`/`Set`——**全部合法,正常使用**。**例外:`@Component`(V1)struct 内的 getter accessor 会被编译转换丢弃,禁用,改用普通成员方法**(`@ComponentV2` 不受此限)。
222
+
223
+ ## 参考
224
+
225
+ - 错误码速查见 [18-error-code](../quick-apis/18-error-code.md)
226
+ - 空安全回调场景高发错误见 [09-attribute-params](07-attribute-params.md) 空安全节
227
+ - kit 归属和速查表见 [01-import](01-import.md)
228
+ - 对象字面量类型约束见 [10-type-annotation](00-arkts-syntax.md)
229
+ - 命名冲突(struct 名 ≠ imported 类型名、跨文件重名)见 [03-component](03-component.md)
@@ -0,0 +1,116 @@
1
+ # 1. 模块导入(import)约束
2
+
3
+ ## 规则
4
+
5
+ | 规则 | 说明 |
6
+ |------|------|
7
+ | **禁止使用 `@ohos.*` 路径导入** | 旧版导入路径,**必须用 `@kit.*` 替代**。`import router from '@ohos.router'` → `import { router } from '@kit.ArkUI'` |
8
+ | **禁止凭记忆编造 import** | 模块路径和导出符号必须来自检索结果/速查表,不得猜测 |
9
+ | **禁止遗漏必要的 import** | 代码中使用的外部类型/函数/枚举必须有对应 import 声明 |
10
+ | **禁止 import 未使用的模块** | 导入了但未使用的模块必须删除 |
11
+ | **禁止从错误 kit 导入** | 每个 API 只属于一个 kit,不能从错误的 kit 导入(参考下方速查表) |
12
+
13
+ ## Kit 导入速查表
14
+
15
+ ### @kit.ArkUI(UI 开发核心 kit)
16
+
17
+ ```ts
18
+ import {
19
+ UIContext, window, BuilderNode, FrameNode, NodeController,
20
+ ComponentContent, NodeContent, NodeRenderState,
21
+ LengthMetrics, ColorMetrics, matrix4, curves,
22
+ router, PromptAction, ImageModifier, KeyboardAvoidMode,
23
+ Font, uiObserver, UIUtils,
24
+ Theme, ThemeControl, CustomColors, CustomTheme,
25
+ CircleShape, RectShape, EllipseShape, PathShape, Binding
26
+ } from '@kit.ArkUI'
27
+ ```
28
+
29
+ | 使用场景 | 导入符号 |
30
+ |---------|---------|
31
+ | UI 上下文操作 | `UIContext` |
32
+ | 窗口管理 | `window` |
33
+ | 自定义节点 | `BuilderNode`, `FrameNode`, `NodeController` |
34
+ | 自定义内容 | `ComponentContent`, `NodeContent` |
35
+ | 节点渲染状态 | `NodeRenderState` |
36
+ | 尺寸/颜色度量 | `LengthMetrics`, `ColorMetrics` |
37
+ | 矩阵变换 / 动画曲线 | `matrix4`, `curves` |
38
+ | 页面路由 / 弹窗提示 | `router`, `PromptAction` |
39
+ | 图片属性修改器 / 键盘避让 | `ImageModifier`, `KeyboardAvoidMode` |
40
+ | 自定义字体 / UI 观察者 | `Font`, `uiObserver` |
41
+ | V1/V2 兼容工具 | `UIUtils` |
42
+ | 主题相关 | `Theme`, `ThemeControl`, `CustomColors`, `CustomTheme` |
43
+ | Shape 裁切 | `CircleShape`, `RectShape`, `EllipseShape`, `PathShape` |
44
+ | 数据绑定 | `Binding` |
45
+
46
+ ### @kit.AbilityKit(应用模型 kit)
47
+
48
+ ```ts
49
+ import { UIAbility, AbilityConstant, Want, common, Configuration, ConfigurationConstant, bundleManager } from '@kit.AbilityKit'
50
+ ```
51
+
52
+ | 使用场景 | 导入符号 |
53
+ |---------|---------|
54
+ | Ability 生命周期 | `UIAbility`, `AbilityConstant` |
55
+ | Ability 间通信 | `Want` |
56
+ | 获取上下文类型 | `common`(如 `common.UIAbilityContext`) |
57
+ | 配置变更 / 包管理 | `Configuration`, `ConfigurationConstant`, `bundleManager` |
58
+
59
+ ### @kit.BasicServicesKit(基础服务 kit)
60
+
61
+ ```ts
62
+ import { BusinessError, request, commonEventManager } from '@kit.BasicServicesKit'
63
+ ```
64
+
65
+ | 使用场景 | 导入符号 |
66
+ |---------|---------|
67
+ | 错误类型捕获 | `BusinessError` |
68
+ | 网络下载 / 公共事件 | `request`, `commonEventManager` |
69
+
70
+ ### 其他 kit
71
+
72
+ | Kit | 导入符号 | 使用场景 |
73
+ |-----|---------|---------|
74
+ | `@kit.ArkData` | `unifiedDataChannel`, `uniformTypeDescriptor` | 拖拽数据传递(UTD) |
75
+ | `@kit.ImageKit` | `image` | 图片处理(编解码、缩放等) |
76
+ | `@kit.InputKit` | `pointer`, `IntentionCode` | 光标样式、输入设备 |
77
+ | `@kit.ArkGraphics2D` | `uiEffect` | 模糊效果等图形能力 |
78
+ | `@kit.CoreFileKit` | `fileIo` | 文件读写 |
79
+ | `@kit.ArkTS` | `buffer` | 二进制缓冲区 |
80
+ | `@kit.PerformanceAnalysisKit` | `hilog` | 日志输出 |
81
+
82
+ ## 全局内置(不需要 import)
83
+
84
+ 基础组件(`Column/Row/Text/Button/Image/List/Grid/Scroll/Stack/Flex/Tabs/Navigation/NavDestination/TextInput` 等)、控制器类型(`SwiperController/TextInputController/Scroller/NavPathStack` 等直接 `new`)、渲染控制(`ForEach/LazyForEach/if-else`)、`AttributeModifier`/`AttributeUpdater` 等扩展接口、枚举(`Color/FontWeight/Curve/FlexAlign/Alignment/Axis/ImageFit/InputType/ButtonType/TextAlign/TextOverflow/Visibility/PlayMode` 等)全局可用。
85
+
86
+ **特别注意以下全局类型不要 import(`@kit.ArkUI` 不导出它们):**
87
+ - `NavPathStack`、`AppStorage`、`canIUse`、`getContext` — 全局可用,不要 import
88
+ - `ObservedV2`、`Trace` — 装饰器全局可用,不要 import
89
+ - `Resource`、`ResourceColor`、`ResourceStr` — 全局类型,不要 import
90
+ - `AlertDialog`、`ActionSheet`、`DatePickerDialog`、`TimePickerDialog`、`TextPickerDialog` — 弹窗全局可用(但建议通过 UIContext 调用)
91
+ - `LocalStorage`、`PersistentStorage`、`AppStorage` — 状态类型全局可用
92
+
93
+ **以下需要 import:**
94
+ - `AppStorageV2`、`PersistenceV2` — **需要**从 `@kit.ArkUI` 导入
95
+ - 小写 `curves` 命名空间 — **需要**从 `@kit.ArkUI` 导入(`Curve.*` 枚举是全局的)
96
+
97
+ > **注意**:`AttributeModifier` 不要在 `@kit.ArkUI` 里 import,它在全局 component 作用域(实测 TC_EXT_COMPONENT_001)。
98
+
99
+ ## 常见错误对比
100
+
101
+ | ❌ 错误写法 | ✅ 正确写法 |
102
+ |-----------|-----------|
103
+ | `import router from '@ohos.router'` | `import { router } from '@kit.ArkUI'` |
104
+ | `import window from '@ohos.window'` | `import { window } from '@kit.ArkUI'` |
105
+ | `import promptAction from '@ohos.promptAction'` | `import { PromptAction } from '@kit.ArkUI'`(或通过 UIContext 获取) |
106
+ | `import { BusinessError } from '@ohos.base'` | `import { BusinessError } from '@kit.BasicServicesKit'` |
107
+ | `import { UIAbility } from '@kit.ArkUI'` | `import { UIAbility } from '@kit.AbilityKit'` |
108
+ | `import { hilog } from '@kit.ArkUI'` | `import { hilog } from '@kit.PerformanceAnalysisKit'` |
109
+ | `import { image } from '@kit.ArkUI'` | `import { image } from '@kit.ImageKit'` |
110
+ | `import { fileIo } from '@kit.ArkUI'` | `import { fileIo } from '@kit.CoreFileKit'` |
111
+ | `import { mediaQuery } from '@kit.ArkUI'`(小写 q) | `import { MediaQuery } from '@kit.ArkUI'`(大写 Q) |
112
+
113
+ ## 参考
114
+
115
+ - **关键**:ArkTS 全局内置能力已在上文列出;凡是不在列表中的,必须先查速查表或检索确认再写,不凭记忆编造
116
+ - 组件/struct 基本约束见 [03-component](03-component.md):创建组件不需要 `new`;`struct` 无继承;static 无意义;组件名不得与系统组件重名
@@ -0,0 +1,56 @@
1
+ # 2. UIContext — 全局接口必须通过 `getUIContext()`
2
+
3
+ ## 规则
4
+
5
+ Stage 模型下一个 ArkTS 引擎可运行多个 ArkUI 实例,全局接口通过分析调用链中的上下文信息确定当前 UI 上下文,异步接口和非 UI 接口可能导致 UI 上下文跟踪失败。**禁止直接使用全局接口,必须通过 `UIContext` 获取替代接口。**
6
+
7
+ 获取方式:组件内 `this.getUIContext()`;窗口侧 `windowClass.getUIContext()`。
8
+
9
+ ## 全局接口 → UIContext 替换表(高频)
10
+
11
+ | ❌ 禁止的全局接口 | ✅ UIContext 替代 | 说明 |
12
+ |---|---|---|
13
+ | `AlertDialog.show` | `uiContext.showAlertDialog()` | |
14
+ | `ActionSheet.show` | `uiContext.showActionSheet()` | |
15
+ | `router.*` | `uiContext.getRouter().*` | |
16
+ | `promptAction.*` | `uiContext.getPromptAction().*` | |
17
+ | `vp2px/px2vp/fp2px/px2fp` | `uiContext.vp2px()` 等(直接方法) | |
18
+ | `animateTo` | `uiContext.animateTo()` | |
19
+ | `@ohos.mediaquery` | `uiContext.getMediaQuery()` | |
20
+ | `@ohos.font` | `uiContext.getFont()` | |
21
+ | `@ohos.measure` | `uiContext.getMeasureUtil()` | 文本计算 |
22
+ | `@ohos.animator` | `uiContext.createAnimator()` | |
23
+ | `@ohos.arkui.observer` | `uiContext.getUIObserver()` | 无感监听 |
24
+ | `@ohos.arkui.dragController` | `uiContext.getDragController()` | |
25
+ | `@ohos.arkui.componentSnapshot` | `uiContext.getComponentSnapshot()` | 组件截图 |
26
+ | `@ohos.arkui.componentUtils` | `uiContext.getComponentUtils()` | |
27
+ | `@ohos.arkui.inspector` | `uiContext.getUIInspector()` | 组件布局回调 |
28
+ | `focusControl` | `uiContext.getFocusController()` | |
29
+ | `cursorControl` | `uiContext.getCursorControl()` | |
30
+ | `getContext` | `uiContext.getHostContext()` | 获取当前 Ability 的 Context |
31
+ | `LocalStorage.getShared` | `uiContext.getSharedLocalStorage()` | |
32
+ | `CalendarPickerDialog.show` | `uiContext.runScopedTask(() => CalendarPickerDialog.show(...))` | 无直接替代,需 runScopedTask 包裹 |
33
+ | `DatePickerDialog` | `uiContext.showDatePickerDialog()` | |
34
+ | `TimePickerDialog` | `uiContext.showTimePickerDialog()` | |
35
+ | `TextPickerDialog` | `uiContext.showTextPickerDialog()` | |
36
+ | `ContextMenu` | `uiContext.getContextMenuController()` | |
37
+ | `lpx2px` / `px2lpx` | `uiContext.lpx2px()` 等(直接方法) | |
38
+ | `keyframeAnimateTo` | `uiContext.keyframeAnimateTo(param, keyframes)` | **存在**,但**不支持** springMotion/responsiveSpringMotion/interpolatingSpring |
39
+ | `animateToImmediately` | **无替换,禁止使用** | |
40
+
41
+ ## 常见错误对比
42
+
43
+ | ❌ 错误写法 | ✅ 正确写法 |
44
+ |------------|-----------|
45
+ | `AlertDialog.show({ message: 'x' })` | `this.getUIContext().showAlertDialog({ message: 'x' })` |
46
+ | `router.pushUrl({ url: 'pages/Second' })` | `this.getUIContext().getRouter().pushUrl({ url: 'pages/Second' })` |
47
+ | `promptAction.showToast({ message: 'hi' })` | `this.getUIContext().getPromptAction().showToast({ message: 'hi' })` |
48
+ | `let px = vp2px(20)` | `let px = this.getUIContext().vp2px(20)` |
49
+ | `animateTo({ duration: 300 }, () => {})` | `this.getUIContext().animateTo({ duration: 300 }, () => {})` |
50
+
51
+ **根因**:AI 训练数据中直接调用全局接口的示例很多,且语法上不报错但在多实例场景会出问题。
52
+
53
+ ## 参考
54
+
55
+ - 动画顺序与限制见 [05-state-v1](05-state.md) @Builder 部分和 [13-style](10-style.md) 动画约束
56
+ - 废弃接口替换见 [19-deprecated](14-deprecated.md)
@@ -0,0 +1,105 @@
1
+ # 3. 自定义组件与命名约束
2
+
3
+ ## 规则
4
+
5
+ ### 组件基本约束
6
+
7
+ | 规则 | 说明 | 错误码 |
8
+ |------|------|--------|
9
+ | `struct` 无继承 | 自定义组件基于 struct,**不能有继承关系** | — |
10
+ | 禁止名称冲突 | 自定义组件名、类名、函数名**不得与系统组件名重复**(`Button`/`Text`/`Image` 等) | — |
11
+ | 单一 `@Entry` | 单个 UI 页面仅允许一个 `@Entry` 装饰的组件 | — |
12
+ | `@Component` 与 `@ComponentV2` 互斥 | 不能同时装饰同一个 struct | — |
13
+ | 创建组件不需要 `new` | `Column()`、`Text('x')`;只有控制器类用 `new`(`new NavPathStack()`) | — |
14
+ | 成员函数/变量不建议 `static` | 仅能从组件内部访问,静态声明无意义 | — |
15
+ | V1 不支持静态代码块 | `@Component` 或 `@CustomDialog` 中 `static {}` 不执行(API 22 起告警) | — |
16
+ | `@Component`(V1)禁 getter accessor | 编译转换会丢弃 getter,可能造成运行时崩溃;改用普通成员方法(`@ComponentV2` 不受此限) | — |
17
+ | 生命周期钩子不能 `private` | `aboutToAppear`、`aboutToDisappear` 等生命周期方法**不能标记为 `private`** | — |
18
+ | 成员属性名禁止与链式方法重名 | 见下方"保留名"清单 | **10505001** |
19
+ | 跨文件 interface/class 必须重名校验 | 同一 hap 全局作用域,通用名跨文件碰撞 → `arkts-no-decl-merging` | **arkts-no-decl-merging** |
20
+
21
+ ### 成员变量名禁止与 CustomComponent 链式方法/通用属性重名
22
+
23
+ `@State/@Prop/@Local` 等成员名**禁止**使用以下(会与基类链式方法签名冲突,触发 `10505001`):
24
+
25
+ `id`、`width`、`height`、`margin`、`padding`、`offset`、`position`、`border`、`borderRadius`、`backgroundColor`、`brightness`、`direction`、`value`、`scale`、`rotate`、`opacity`、`visibility`、`zIndex`、`size`、`layoutWeight`、`aspectRatio`、`flexBasis`、`flexGrow`、`flexShrink`、`alignSelf`、`justifyContent`、`alignItems`、`alignContent`、`borderWidth`、`borderColor`、`borderStyle`、`borderImage`、`foregroundColor`、`colorFilter`、`clip`、`gradient`、`blur`、`shadow`、`transform`、`markAnchor`、`translate`、`clickEffect`、`hoverEffect`、`draggable`、`enabled`、`tabIndex`(所有通用属性名 + CustomComponent 基类属性均为禁区)
26
+
27
+ 命名约定:用业务前缀(`current/slide/item/bg/screen/my` 等)消歧义,如 `currentValue` 而非 `value`。
28
+
29
+ ### 跨文件 interface/class 重名 → `arkts-no-decl-merging`(CRITICAL)
30
+
31
+ ArkTS 把同一 hap 内**所有页面**编译进**共享全局作用域**。多个页面文件在顶层声明同名 `interface`/`class`,会被判定为"声明合并"而报错。**碰撞发生在文件之间,本文件内看不到。** 命名之前需要避免重名存在。
32
+
33
+ ## 框架保留字全表
34
+
35
+ 自定义组件中定义的方法/变量若与下表重名,会导致运行时异常。凡列出的,一律改用不同名字。
36
+
37
+ | 保留字 | 保留字 | 保留字 | 保留字 |
38
+ |---|---|---|---|
39
+ | isRenderInProgress | isInitialRenderDone | runReuse_ | paramsGenerator_ |
40
+ | watchedProps | recycleManager_ | hasBeenRecycled_ | preventRecursiveRecycle_ |
41
+ | delayRecycleNodeRerender | delayRecycleNodeRerenderDeep | defaultConsume_ | reconnectConsume_ |
42
+ | providedVars_ | dirtyElementIdsNeedsUpdateSynchronously_ | localStoragebackStore_ | ownObservedPropertiesStore__ |
43
+ | obtainOwnObservedProperties | getlocalStorage_ | setlocalStorage_ | getisViewV2 |
44
+ | aboutToBeDeleted | aboutToBeDeletedInternal | purgeDeleteElmtId | purgeVariableDependenciesOnElmtIdOwnFunc |
45
+ | debugInfoStateVars | initAllowComponentFreeze | setActiveInternal | onActiveInternal |
46
+ | onInactiveInternal | purgeVariableDependenciesOnElmtId | initialRender | rerender |
47
+ | updateRecycleElmtId | updateStateVars | initialRenderView | UpdateElement |
48
+ | delayCompleteRerender | flushDelayCompleteRerender | forceRerenderNode | collectElementsNeedToUpdateSynchronously |
49
+ | viewPropertyHasChanged | uiNodeNeedUpdateV2 | performDelayedUpdate | declareWatch |
50
+ | addProvidedVar | findProvidePU__ | initializeConsume | reconnectToConsume |
51
+ | disconnectedConsume | markElemenDirtyById | updateDirtyElements | observeComponentCreation |
52
+ | observeComponentCreation2 | getOrCreateRecycleManager | getRecycleManager | hasRecycleManager |
53
+ | initRecycleManager | rebuildUpdateFunc | observeRecycleComponentCreation | aboutToReuseInternal |
54
+ | stopRecursiveRecycle | aboutToRecycleInternal | recycleSelf | isRecycled |
55
+ | UpdateLazyForEachElements | createStorageLink | createStorageProp | createLocalStorageLink |
56
+ | createLocalStorageProp | debugInfoView | debugInfoViewInternal | debugInfoDirtyDescendantElementIds |
57
+ | __mkRepeatAPI | reuseOrCreateNewComponent | dirtDescendantElementIds_ | monitorIdsDelayedUpdate |
58
+ | monitorIdsDelayedUpdateForAddMonitor_ | computedIdsDelayedUpdate | recyclePoolV2_ | resetStateVarsOnReuse |
59
+ | aboutToReuseInternals | resetMonitorsOnReuse | resetComputed | resetConsumer |
60
+ | initParam | updateParam | resetParam | getViewV2ChildById |
61
+ | addDelayedMonitorIdsForAddMonitor | addDelayedComputedIds | inactiveComponents_ | compareNumber |
62
+ | currentlyRenderedElmtIdStack_ | dirtRetakenElementIds_ | parent_ | renderingPaused |
63
+ | isDeleting_ | isCompFreezeAllowed_ | prebuildFuncQueues | propertyChangedFuncQueues |
64
+ | extraInfo_ | __isBlockRecycleOrReuse__ | elmtIdsDelayedUpdate_ | prebuildPhase_ |
65
+ | isPrebuilding_ | prebuildingElmtId_ | doRecycle | doReuse |
66
+ | nativeViewPartialUpdate | create | createRecycle | markNeedUpdate |
67
+ | syncInstanceId | restoreInstanceId | getInstanceId | markStatic |
68
+ | finishUpdateFunc | setCardId | getCardId | elmtIdExists |
69
+ | isLazyItemRender | isFirstRender | findChildByIdForPreview | resetRecycleCustomNode |
70
+ | queryNavDestinationInfo | queryNavigationInfo | queryRouterPageInfo | getUIContext |
71
+ | sendStateInfo | getUniqueId | setIsV2 | getDialogController |
72
+ | allowReusableV2Descendant | id__ | updateId | scheduleDelayedUpdate |
73
+ | setParent | getParent | removeChild | addChild |
74
+ | isDeleting | setDeleting | setDeleteStatusRecursively | setActiveCount |
75
+ | getChildViewV2ForElmtId | debugInfoRegisteredElmtIds | debugInfoElmtIds | dumpStateVars |
76
+ | isViewActive | dumpReport | forceCompleteRerender | __ClearAllRecycle__PUV2ViewBase__Internal |
77
+ | hasNodeUpdateFunc | pauseRendering | restoreRendering | forEachUpdateFunction |
78
+ | getNodeById | getCurrentlyRenderedElmtId | debugInfoViewHierarchy | debugInfoUpdateFuncByElmtId |
79
+ | debugInfoInactiveComponents | findViewInHierarchy | onDumpInfo | printDFXHeader |
80
+ | processOnDumpCommands | traverseChildDoRecycleOrReuse | processPropertyChangedFuncQueue | setPrebuildPhase |
81
+ | isNeedBuildPrebuildCmd | prebuildComponent | isEnablePrebuildInMultiFrame | ifElseBranchUpdateFunctionDirtyRetaken |
82
+ | onDumpInspector | activeCount_ | isView_ | childrenWeakrefMap_ |
83
+ | builderNodeWeakrefMap_ | updateFuncByElmtId | id_ | shareLocalStorage_ |
84
+ | __parentViewBuildNode__ | __enableBuilderNodeConsume__ | __elmtId2Repeat___ | arkThemeScopeManager |
85
+ | setArkThemeScopeManager | onWillApplyThemeInternally | getShareLocalStorage | setShareLocalStorage |
86
+ | propagateToChildren | propagateToChildrenToConnected | propagateToChildrenToDisconnected | addChildBuilderNode |
87
+ | setParentBuilderNode__ | removeChildBuilderNode | clearChildBuilderNode | getChildById |
88
+ | purgeDeletedElmtIds | updateStateVarsOfChildByElmtId | createOrGetNode | ifElseBranchUpdateFunction |
89
+
90
+ > 高频禁区:`rerender/aboutToAppear/aboutToDisappear/aboutToReuse/aboutToRecycle/initialRender/updateStateVars/getUIContext/observeComponentCreation/create/setParent/getParent/addChild/removeChild/markNeedUpdate/forceRerenderNode/findProvidePU__/isViewV2/localStorage_/id__/elmtIdsDelayedUpdate/recycleManager_` 等。`getUIContext` 本身也是保留名,不要 shadow。
91
+
92
+ ## 常见错误对比
93
+
94
+ | ❌ 错误写法 | ✅ 正确写法 | 说明 |
95
+ |------------|-----------|------|
96
+ | `struct Button {}` | `struct MyButton {}` | 与系统组件名冲突 |
97
+ | `@State value: string = ''` | `@State currentValue: string = ''` | 与 `.value()` 冲突 → 10505001 |
98
+ | `@State direction: number = 0` | `@State moveDirection: number = 0` | 与 `.direction` 冲突 |
99
+ | `@State position: number = 0` | `@State slotPosition: number = 0` | 与 `.position` 冲突 |
100
+ | 变量命名 `rerender` | `rerenderValue` | 与框架保留字冲突 |
101
+
102
+ ## 参考
103
+
104
+ - 容器直接子组件约束见 [16-layout](12-layout.md)
105
+ - 成员变量命名与链式方法冲突(错误码 10505001)