deveco-harness 0.1.0

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 (135) hide show
  1. package/README.en.md +71 -0
  2. package/README.md +71 -0
  3. package/deveco-harness.example.jsonc +32 -0
  4. package/dist/index.js +758 -0
  5. package/package.json +48 -0
  6. package/prompts/build.txt +164 -0
  7. package/prompts/plan.txt +118 -0
  8. package/skills/arkts-error-fixes/README.md +151 -0
  9. package/skills/arkts-error-fixes/SKILL.md +150 -0
  10. package/skills/arkts-error-fixes/assets/AnyTypeError.ets +269 -0
  11. package/skills/arkts-error-fixes/assets/AppStorageError.ets +22 -0
  12. package/skills/arkts-error-fixes/assets/ArrowFunctionConversionError.ets +42 -0
  13. package/skills/arkts-error-fixes/assets/AvoidAreaTypeError.ets +43 -0
  14. package/skills/arkts-error-fixes/assets/BreakpointTypeError.ets +71 -0
  15. package/skills/arkts-error-fixes/assets/CatchClauseTypeError.ets +54 -0
  16. package/skills/arkts-error-fixes/assets/ColorConsistencyError.ets +88 -0
  17. package/skills/arkts-error-fixes/assets/ColorPropertyError.ets +39 -0
  18. package/skills/arkts-error-fixes/assets/ContextTypeError.ets +105 -0
  19. package/skills/arkts-error-fixes/assets/DecoratorStateError.ets +64 -0
  20. package/skills/arkts-error-fixes/assets/DisplayListenerTypeError.ets +129 -0
  21. package/skills/arkts-error-fixes/assets/DuplicateEntryError.ets +35 -0
  22. package/skills/arkts-error-fixes/assets/ESObjectTypeError.ets +137 -0
  23. package/skills/arkts-error-fixes/assets/FontColorPropertyError.ets +42 -0
  24. package/skills/arkts-error-fixes/assets/FunctionReturnTypeError.ets +41 -0
  25. package/skills/arkts-error-fixes/assets/IDataSourceError.ets +79 -0
  26. package/skills/arkts-error-fixes/assets/ImplementationNotAllowedError.ets +38 -0
  27. package/skills/arkts-error-fixes/assets/InterfaceMethodSignatureError.ets +43 -0
  28. package/skills/arkts-error-fixes/assets/NotificationError.ets +34 -0
  29. package/skills/arkts-error-fixes/assets/ObjectLiteralInterfaceError.ets +49 -0
  30. package/skills/arkts-error-fixes/assets/ObjectLiteralTypeError.ets +54 -0
  31. package/skills/arkts-error-fixes/assets/ObjectSpreadError.ets +29 -0
  32. package/skills/arkts-error-fixes/assets/PossiblyNullError.ets +32 -0
  33. package/skills/arkts-error-fixes/assets/ResourceConversionError.ets +159 -0
  34. package/skills/arkts-error-fixes/assets/StandaloneFunctionContext.ets +116 -0
  35. package/skills/arkts-error-fixes/assets/StandaloneFunctionError.ets +85 -0
  36. package/skills/arkts-error-fixes/assets/StorageLinkDefaultError.ets +41 -0
  37. package/skills/arkts-error-fixes/assets/TitleButtonRectTypeError.ets +86 -0
  38. package/skills/arkts-error-fixes/assets/UnusedVariableWarning.ets +102 -0
  39. package/skills/arkts-error-fixes/assets/UtilityTypeError.ets +176 -0
  40. package/skills/arkts-error-fixes/assets/WindowRectSizeError.ets +65 -0
  41. package/skills/arkts-error-fixes/assets/WindowTypeError.ets +37 -0
  42. package/skills/arkts-error-fixes/reference/any_type_errors.md +433 -0
  43. package/skills/arkts-error-fixes/reference/appstorage_errors.md +95 -0
  44. package/skills/arkts-error-fixes/reference/arrow_function_conversion_errors.md +163 -0
  45. package/skills/arkts-error-fixes/reference/avoid_area_type_errors.md +59 -0
  46. package/skills/arkts-error-fixes/reference/breakpoint_type_errors.md +122 -0
  47. package/skills/arkts-error-fixes/reference/catch_clause_type_errors.md +89 -0
  48. package/skills/arkts-error-fixes/reference/color_consistency_errors.md +209 -0
  49. package/skills/arkts-error-fixes/reference/color_property_errors.md +136 -0
  50. package/skills/arkts-error-fixes/reference/context_type_errors.md +260 -0
  51. package/skills/arkts-error-fixes/reference/decorator_state_errors.md +109 -0
  52. package/skills/arkts-error-fixes/reference/display_listener_type_errors.md +149 -0
  53. package/skills/arkts-error-fixes/reference/duplicate_entry_errors.md +193 -0
  54. package/skills/arkts-error-fixes/reference/esobject_type_errors.md +110 -0
  55. package/skills/arkts-error-fixes/reference/fontcolor_property_errors.md +104 -0
  56. package/skills/arkts-error-fixes/reference/function_return_type_errors.md +194 -0
  57. package/skills/arkts-error-fixes/reference/idata_source_errors.md +77 -0
  58. package/skills/arkts-error-fixes/reference/implementation_not_allowed_errors.md +191 -0
  59. package/skills/arkts-error-fixes/reference/interface_method_signature_errors.md +143 -0
  60. package/skills/arkts-error-fixes/reference/notification_errors.md +110 -0
  61. package/skills/arkts-error-fixes/reference/object_literal_interface_errors.md +156 -0
  62. package/skills/arkts-error-fixes/reference/object_literal_type_errors.md +110 -0
  63. package/skills/arkts-error-fixes/reference/object_spread_errors.md +105 -0
  64. package/skills/arkts-error-fixes/reference/possibly_null_errors.md +156 -0
  65. package/skills/arkts-error-fixes/reference/resource_conversion_errors.md +154 -0
  66. package/skills/arkts-error-fixes/reference/standalone_function_errors.md +68 -0
  67. package/skills/arkts-error-fixes/reference/storage_link_default_errors.md +124 -0
  68. package/skills/arkts-error-fixes/reference/title_button_rect_type_errors.md +167 -0
  69. package/skills/arkts-error-fixes/reference/unused_variable_warnings.md +295 -0
  70. package/skills/arkts-error-fixes/reference/utility_type_errors.md +290 -0
  71. package/skills/arkts-error-fixes/reference/window_rect_size_errors.md +70 -0
  72. package/skills/arkts-error-fixes/reference/window_type_errors.md +95 -0
  73. package/skills/arkts-grammar-standards/SKILL.md +71 -0
  74. package/skills/arkts-grammar-standards/references/basic-syntax.md +103 -0
  75. package/skills/arkts-grammar-standards/references/restrictions.md +100 -0
  76. package/skills/arkts-grammar-standards/references/topic-aliases.json +93 -0
  77. package/skills/arkts-grammar-standards/references/ts-diff.md +108 -0
  78. package/skills/arkts-runtime-fix/SKILL.md +152 -0
  79. package/skills/arkts-runtime-fix/SKILL_CN.md +123 -0
  80. package/skills/arkts-runtime-fix/evals/evals.json +17 -0
  81. package/skills/arkts-runtime-fix/scripts/collect-hilog.mjs +116 -0
  82. package/skills/arkts-runtime-fix/scripts/collect-hilog.ts +115 -0
  83. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.mjs +117 -0
  84. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.ts +116 -0
  85. package/skills/arkts-runtime-fix/scripts/jscrash-report.mjs +149 -0
  86. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.mjs +126 -0
  87. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.ts +126 -0
  88. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.mjs +160 -0
  89. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.ts +160 -0
  90. package/skills/arkts-runtime-fix/scripts/shared/hdc.mjs +107 -0
  91. package/skills/arkts-runtime-fix/scripts/shared/hdc.ts +58 -0
  92. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.mjs +143 -0
  93. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.ts +148 -0
  94. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.mjs +389 -0
  95. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.ts +409 -0
  96. package/skills/arkts-runtime-fix/scripts/shared/utils.mjs +27 -0
  97. package/skills/arkts-runtime-fix/scripts/shared/utils.ts +27 -0
  98. package/skills/arkui-knowledge/SKILL.md +90 -0
  99. package/skills/arkui-knowledge/references/api-guardrails.md +60 -0
  100. package/skills/arkui-knowledge/references/common-mistakes.md +119 -0
  101. package/skills/arkui-knowledge/references/component-cookbook.md +135 -0
  102. package/skills/arkui-knowledge/references/ui-quality-checklist.md +36 -0
  103. package/skills/deveco-create-project/SKILL.md +144 -0
  104. package/skills/deveco-create-project/application/AppScope/app.json5 +10 -0
  105. package/skills/deveco-create-project/application/AppScope/resources/base/element/string.json +8 -0
  106. package/skills/deveco-create-project/application/AppScope/resources/base/media/background.png +0 -0
  107. package/skills/deveco-create-project/application/AppScope/resources/base/media/foreground.png +0 -0
  108. package/skills/deveco-create-project/application/AppScope/resources/base/media/layered_image.json +7 -0
  109. package/skills/deveco-create-project/application/build-profile.json5 +42 -0
  110. package/skills/deveco-create-project/application/code-linter.json5 +32 -0
  111. package/skills/deveco-create-project/application/entry/build-profile.json5 +33 -0
  112. package/skills/deveco-create-project/application/entry/hvigorfile.ts +7 -0
  113. package/skills/deveco-create-project/application/entry/obfuscation-rules.txt +23 -0
  114. package/skills/deveco-create-project/application/entry/oh-package.json5 +10 -0
  115. package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
  116. package/skills/deveco-create-project/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
  117. package/skills/deveco-create-project/application/entry/src/main/ets/pages/Index.ets +38 -0
  118. package/skills/deveco-create-project/application/entry/src/main/module.json5 +50 -0
  119. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/color.json +8 -0
  120. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/float.json +8 -0
  121. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/string.json +16 -0
  122. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png +0 -0
  123. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png +0 -0
  124. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/layered_image.json +7 -0
  125. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png +0 -0
  126. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
  127. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
  128. package/skills/deveco-create-project/application/entry/src/main/resources/dark/element/color.json +8 -0
  129. package/skills/deveco-create-project/application/hvigor/hvigor-config.json5 +23 -0
  130. package/skills/deveco-create-project/application/hvigorfile.ts +7 -0
  131. package/skills/deveco-create-project/application/oh-package.json5 +10 -0
  132. package/skills/deveco-create-project/scripts/copy-template.mjs +216 -0
  133. package/skills/deveco-create-project/scripts/copy-template.ts +214 -0
  134. package/skills/deveco-create-project/scripts/detect-sdk.mjs +82 -0
  135. package/skills/deveco-create-project/scripts/detect-sdk.ts +95 -0
@@ -0,0 +1,95 @@
1
+ # Window API Type Errors
2
+
3
+ ## Error: `window.getLastWindow` type inference issue
4
+
5
+ ### Error Message
6
+ ```
7
+ Type 'void & Promise<Window>' errors
8
+ ```
9
+
10
+ ### Cause
11
+ Using async/await pattern with `window.getLastWindow()` causes type inference issues in ArkTS. The function signature doesn't properly resolve to a Promise type when used with await.
12
+
13
+ ### Solution
14
+ Use the callback pattern instead of async/await for `window.getLastWindow()`.
15
+
16
+ ### Key Points
17
+ - Use callback pattern: `window.getLastWindow(context, (err, win) => { ... })`
18
+ - Always check error code: `if (err.code !== 0)`
19
+ - Handle errors gracefully with console logging
20
+ - Use explicit type annotation for size: `(size: window.Size) => void`
21
+
22
+ ### Callback Pattern
23
+ ```typescript
24
+ window.getLastWindow(context, (err, win) => {
25
+ if (err.code !== 0) {
26
+ console.error('Failed to get window:', err);
27
+ return;
28
+ }
29
+
30
+ // Use window instance
31
+ const properties = win.getWindowProperties();
32
+ });
33
+ ```
34
+
35
+ ### Window Properties
36
+ ```typescript
37
+ interface WindowProperties {
38
+ windowRect: Rect; // Window position and size
39
+ type: WindowType; // Window type
40
+ mode: WindowMode; // Window mode
41
+ brightness: number; // Brightness (0.0-1.0)
42
+ isPrivacyMode: boolean; // Privacy mode status
43
+ isFullScreen: boolean; // Full screen status
44
+ layoutMode: LayoutMode; // Layout mode
45
+ }
46
+
47
+ interface Rect {
48
+ left: number; // Left position
49
+ top: number; // Top position
50
+ width: number; // Width
51
+ height: number; // Height
52
+ }
53
+ ```
54
+
55
+ ### Window Size Change Event
56
+ ```typescript
57
+ win.on('windowSizeChange', (size: window.Size) => {
58
+ console.info(`New size: ${size.width}x${size.height}`);
59
+ });
60
+
61
+ interface Size {
62
+ width: number; // New width
63
+ height: number; // New height
64
+ }
65
+ ```
66
+
67
+ ### Common Window Events
68
+ ```typescript
69
+ win.on('windowSizeChange', (size: window.Size) => { });
70
+ win.on('systemBarTintChange', (region: Region) => { });
71
+ win.on('windowEvent', (data: WindowEvent) => { });
72
+ win.on('avoidAreaChange', (data: AvoidArea) => { });
73
+ ```
74
+
75
+ ### Error Handling
76
+ ```typescript
77
+ // Check for specific error codes
78
+ if (err.code === 1300001) {
79
+ // Invalid parameter
80
+ } else if (err.code === 1300002) {
81
+ // Window not found
82
+ } else if (err.code === 1300003) {
83
+ // Window operation failed
84
+ }
85
+ ```
86
+
87
+ ### Best Practices
88
+ 1. **Always check error code**: Never assume success
89
+ 2. **Log errors**: Use console.error for debugging
90
+ 3. **Clean up listeners**: Remove event listeners in `aboutToDisappear()`
91
+ 4. **Use type annotations**: Explicit types prevent inference issues
92
+ 5. **Handle window state**: Account for window resize and orientation changes
93
+
94
+ ### Related Files
95
+ - [Code Example](../assets/WindowTypeError.ets)
@@ -0,0 +1,71 @@
1
+ ---
2
+ name: arkts-grammar-standards
3
+ description: Load this skill when writing or modifying .ets files. Use it for ArkTS syntax rules, ArkTS-specific restrictions, TypeScript-to-ArkTS syntax differences, syntax compliance review, and ArkTS syntax questions.
4
+ ---
5
+
6
+ # arkts-grammar-standards
7
+
8
+ Use this skill before authoring ArkTS code and to answer ArkTS syntax and restriction questions with grounded references.
9
+
10
+ ## Core authoring checklist
11
+
12
+ Before writing or modifying `.ets` files:
13
+
14
+ - Treat the code as ArkTS, not generic TypeScript.
15
+ - Do not use `any` or `unknown` unless the user explicitly allows it.
16
+ - Do not use `as` type assertions; use explicit types, constructors, or typed helper functions.
17
+ - Do not rely on structural typing; prefer named classes, interfaces, and explicit `implements` relationships.
18
+ - Do not use dynamic property access such as `obj[key]` as a normal modeling pattern; prefer direct property access with known names.
19
+ - Give object literals explicit type context through typed variables, typed parameters, or class/interface construction.
20
+ - Do not use inline object literal types; define a named interface or class instead.
21
+ - Do not use template literals such as `` `${value}` ``; use string concatenation and explicit conversion.
22
+ - Do not use namespaces as runtime values; import or reference the concrete exported value/type that is needed.
23
+ - Avoid restricted TypeScript patterns such as destructuring declarations, destructuring parameters, function expressions, nested local function declarations, class expressions, `delete`, `in`, `for...in`, and type queries like `typeof Foo`.
24
+
25
+ Prefer the bundled reference files over model memory. Keep the answer focused on:
26
+
27
+ - whether a syntax form is allowed
28
+ - what ArkTS expects instead
29
+ - whether the rule comes from the language guide or from the linter-derived summary
30
+ - which topic best matches the user's code or question
31
+
32
+ ## Reference order
33
+
34
+ Read these files as needed:
35
+
36
+ 1. `references/topic-aliases.json`
37
+ 2. `references/basic-syntax.md`
38
+ 3. `references/restrictions.md`
39
+ 4. `references/ts-diff.md`
40
+
41
+ Use `basic-syntax.md` for normal ArkTS writing patterns.
42
+ Use `restrictions.md` when the question is about forbidden syntax, restricted operators, object literal rules, `Sendable`, or review comments.
43
+ Use `ts-diff.md` when the user is porting TypeScript or asking why a familiar TypeScript pattern does not work in ArkTS.
44
+
45
+ ## Source rules
46
+
47
+ - Treat `basic-syntax.md` and `ts-diff.md` as guide-oriented summaries backed by the bundled ArkTS language guide sections.
48
+ - Treat `restrictions.md` as implementation-derived guidance based on the linter summary. Say that clearly when citing it.
49
+ - Do not present linter-derived restrictions as if they were verbatim official spec text.
50
+ - If both a guide-oriented explanation and a linter restriction apply, mention both and explain the relationship in one or two sentences.
51
+
52
+ ## Response shape
53
+
54
+ Use this format unless the user asks for something else:
55
+
56
+ ```markdown
57
+ - Topic: <short topic>
58
+ - Source: <guide-summary | linter-summary | ts-diff-summary>
59
+ - Reference: <reference file and section>
60
+ - Why it matches: <one sentence>
61
+ - Guidance: <one or two sentences>
62
+ ```
63
+
64
+ If the user shows code, add a short rewrite suggestion after the guidance.
65
+
66
+ ## Working rules
67
+
68
+ - Prefer direct syntax guidance over broad language tutorials.
69
+ - Prefer named ArkTS alternatives such as class, interface, explicit field type, arrow function, or direct property access.
70
+ - Keep citations short and traceable.
71
+ - Do not expand the answer into build, run, debug, or tool workflows unless the user explicitly asks for that after the syntax answer.
@@ -0,0 +1,103 @@
1
+ # ArkTS Basic Syntax
2
+
3
+ This file summarizes high-value ArkTS syntax guidance for common authoring and review questions.
4
+
5
+ ## Variables
6
+
7
+ - Use `let` or `const` for variable declarations.
8
+ - Prefer `const` when the binding does not change.
9
+ - Keep types explicit when inference would be unclear.
10
+
11
+ Reference:
12
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/*`
13
+ - Linter summary: declaration section and `arkts-no-var`
14
+
15
+ ## Classes
16
+
17
+ - Prefer named `class` declarations.
18
+ - Declare fields in the class body.
19
+ - Use constructors to establish valid state.
20
+ - Prefer constructing instances with `new` instead of treating classes as loose object shapes.
21
+
22
+ Reference:
23
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/classes.md`
24
+
25
+ ## Interfaces
26
+
27
+ - Use named interfaces for reusable contracts.
28
+ - Prefer interface or class names over inline object type declarations.
29
+ - Use `implements` to make class contracts explicit.
30
+
31
+ Reference:
32
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/interfaces.md`
33
+
34
+ ## Functions
35
+
36
+ - Prefer arrow functions for function values.
37
+ - Keep return types explicit when the result is not obvious.
38
+ - Use top-level or class methods for reusable logic instead of nested local function declarations.
39
+
40
+ Reference:
41
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/functions.md`
42
+ - Linter summary: function declaration section
43
+
44
+ ## Operators
45
+
46
+ - Use normal arithmetic, comparison, logical, and conditional operators with explicit types.
47
+ - Prefer `===` and `!==`.
48
+ - Use explicit conversions instead of JavaScript-style coercion.
49
+ - Use string concatenation and explicit conversion instead of template literals.
50
+
51
+ Reference:
52
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/advanced-operators.md`
53
+
54
+ ## Strings
55
+
56
+ - Use ordinary string literals and concatenation for formatted text.
57
+ - Convert non-string values explicitly before concatenating when the target expects a string.
58
+ - Avoid template literal syntax such as `` `Count: ${count}` ``.
59
+
60
+ ArkTS style:
61
+
62
+ ```ts
63
+ const label: string = "Count: " + count.toString()
64
+ ```
65
+
66
+ Reference:
67
+ - Linter summary: syntax restriction section
68
+
69
+ ## Object modeling
70
+
71
+ - Prefer named classes and interfaces for stable data models.
72
+ - Use object literals only when there is clear explicit type context.
73
+ - Prefer direct property access with known names.
74
+ - Avoid `Record<string, T>` and dynamic keys when a named interface or class can model the shape.
75
+
76
+ ArkTS style:
77
+
78
+ ```ts
79
+ interface UserLabels {
80
+ name: string
81
+ title: string
82
+ }
83
+
84
+ const labels: UserLabels = {
85
+ name: "Name",
86
+ title: "Title",
87
+ }
88
+ const title: string = labels.title
89
+ ```
90
+
91
+ Reference:
92
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/classes.md`
93
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/interfaces.md`
94
+ - Linter summary: object literal section
95
+
96
+ ## Namespaces and imports
97
+
98
+ - Treat namespaces as declaration or type organization, not runtime objects to pass around.
99
+ - Import or reference the concrete exported class, enum, function, or type that the code needs.
100
+ - If a namespace-like module is needed at runtime, model the runtime value with an explicit class or exported object that ArkTS accepts.
101
+
102
+ Reference:
103
+ - Linter summary: namespace section
@@ -0,0 +1,100 @@
1
+ # ArkTS Restrictions
2
+
3
+ This file summarizes ArkTS-specific restrictions that are especially useful in code review and syntax troubleshooting.
4
+
5
+ Unless noted otherwise, the rules below are derived from the bundled linter summary rather than copied from the official guide text.
6
+
7
+ ## Declarations
8
+
9
+ - Do not use `var`; use `let` or `const`.
10
+ - Do not use destructuring in variable declarations.
11
+ - Do not use destructuring in parameters.
12
+ - Do not rely on `any` or `unknown`.
13
+ - Do not use `as` type assertions as a shortcut around ArkTS type checking.
14
+ - Avoid definite assignment assertions like `!`; in `Sendable` classes they are not allowed.
15
+
16
+ Reference:
17
+ - Linter summary: declaration section
18
+ - Rules: `arkts-no-var`, `arkts-no-destruct-decls`, `arkts-no-destruct-params`, `arkts-no-any-unknown`, `arkts-no-definite-assignment`
19
+ - Project authoring rule: avoid `as` type assertions unless explicitly requested.
20
+
21
+ ## Functions and classes
22
+
23
+ - Do not use nested local function declarations.
24
+ - Do not use function expressions; prefer arrow functions.
25
+ - Do not use generator functions or `yield`.
26
+ - Do not use class expressions.
27
+ - Do not use standalone `this` in free functions.
28
+
29
+ Reference:
30
+ - Linter summary: function and class sections
31
+ - Rules: `arkts-no-nested-funcs`, `arkts-no-func-expressions`, `arkts-no-generators`, `arkts-no-class-literals`, `arkts-no-standalone-this`
32
+
33
+ ## Object and property access
34
+
35
+ - Do not treat object literals as free-form structural types.
36
+ - Do not declare inline object literal types in place of named interfaces or classes.
37
+ - Object literals must have explicit type context, such as a typed variable, typed parameter, or declared class/interface target.
38
+ - Do not depend on dynamic property access as a normal modeling pattern.
39
+ - Avoid `Record<string, T>` when it encourages dynamic indexing; define a named type with known properties instead.
40
+ - Prefer identifier property names and direct dot access.
41
+
42
+ Reference:
43
+ - Linter summary: object literal and property access sections
44
+ - Rules: `arkts-no-structural-typing`, `arkts-no-untyped-obj-literals`, `arkts-no-obj-literals-as-types`, `arkts-no-props-by-index`, `arkts-identifiers-as-prop-names`
45
+
46
+ ## String syntax
47
+
48
+ - Template literals are not supported for ArkTS authoring in this project.
49
+ - Rewrite interpolation to string concatenation with explicit conversion.
50
+
51
+ Example rewrite:
52
+
53
+ ```ts
54
+ const label: string = "Likes: " + likeCount.toString()
55
+ ```
56
+
57
+ Reference:
58
+ - Linter summary: syntax restriction section
59
+
60
+ ## Namespaces
61
+
62
+ - Do not use a namespace itself as a runtime value.
63
+ - Avoid namespace bodies that contain runtime statements; keep namespace-like organization to supported declarations.
64
+ - Prefer importing concrete exported symbols or defining explicit runtime classes/objects.
65
+
66
+ Reference:
67
+ - Linter summary: namespace section
68
+ - Rules: `arkts-no-ns-statements`
69
+
70
+ ## Restricted operators and statements
71
+
72
+ - `delete` is not supported.
73
+ - `in` and `for...in` are restricted.
74
+ - `typeof` is allowed in expression context, but not as a type query.
75
+ - `catch` clauses must not carry an explicit exception type annotation.
76
+ - Destructuring assignment is not supported.
77
+
78
+ Reference:
79
+ - Linter summary: operators and statements sections
80
+ - Rules: `arkts-no-delete`, `arkts-no-in`, `arkts-no-types-in-catch`, `arkts-no-destruct-assignment`, `arkts-no-type-query`
81
+
82
+ ## Sendable-focused restrictions
83
+
84
+ - `Sendable` classes must use explicit field types.
85
+ - `Sendable` field types must themselves be sendable.
86
+ - `Sendable` types must not be initialized directly from object literals or array literals.
87
+ - `Sendable` classes and functions have stricter capture and inheritance rules.
88
+
89
+ Reference:
90
+ - Linter summary: sendable sections
91
+ - Rules: `arkts-sendable-explicit-field-type`, `arkts-sendable-prop-types`, `arkts-sendable-obj-init`, `arkts-sendable-class-inheritance`
92
+
93
+ ## How to cite this file
94
+
95
+ When using this file in an answer, say that the restriction comes from the linter-derived ArkTS summary.
96
+ Use that wording especially for:
97
+
98
+ - forbidden syntax claims
99
+ - `Sendable` restrictions
100
+ - dynamic object model limitations
@@ -0,0 +1,93 @@
1
+ {
2
+ "variables": [
3
+ "var",
4
+ "let",
5
+ "const",
6
+ "变量",
7
+ "变量声明"
8
+ ],
9
+ "destructuring": [
10
+ "destructuring",
11
+ "destructure",
12
+ "解构",
13
+ "解构赋值",
14
+ "解构参数"
15
+ ],
16
+ "functions": [
17
+ "arrow function",
18
+ "function expression",
19
+ "nested function",
20
+ "generator",
21
+ "函数表达式",
22
+ "箭头函数",
23
+ "局部函数"
24
+ ],
25
+ "classes": [
26
+ "class",
27
+ "class expression",
28
+ "constructor",
29
+ "类",
30
+ "构造函数"
31
+ ],
32
+ "interfaces": [
33
+ "interface",
34
+ "inline object type",
35
+ "structural typing",
36
+ "接口",
37
+ "结构类型"
38
+ ],
39
+ "operators": [
40
+ "delete",
41
+ "typeof",
42
+ "in operator",
43
+ "for in",
44
+ "catch",
45
+ "as",
46
+ "type assertion",
47
+ "as const",
48
+ "运算符",
49
+ "类型查询",
50
+ "类型断言"
51
+ ],
52
+ "object-literal": [
53
+ "object literal",
54
+ "dynamic property",
55
+ "indexed access",
56
+ "record",
57
+ "Record",
58
+ "property by index",
59
+ "对象字面量",
60
+ "动态属性",
61
+ "动态索引"
62
+ ],
63
+ "strings": [
64
+ "template literal",
65
+ "template string",
66
+ "${",
67
+ "string interpolation",
68
+ "模板字符串",
69
+ "字符串插值"
70
+ ],
71
+ "namespace": [
72
+ "namespace",
73
+ "namespace as value",
74
+ "Cannot use namespace as a value",
75
+ "命名空间",
76
+ "namespace 作为值"
77
+ ],
78
+ "sendable": [
79
+ "sendable",
80
+ "@sendable",
81
+ "可发送",
82
+ "并发类型"
83
+ ],
84
+ "typescript-diff": [
85
+ "typescript",
86
+ "ts",
87
+ "migration",
88
+ "difference",
89
+ "改写",
90
+ "迁移",
91
+ "差异"
92
+ ]
93
+ }
@@ -0,0 +1,108 @@
1
+ # TypeScript to ArkTS Syntax Differences
2
+
3
+ This file highlights TypeScript patterns that often need rewriting in ArkTS.
4
+
5
+ ## Dynamic JavaScript patterns are narrower
6
+
7
+ - ArkTS is not a drop-in TypeScript superset in practice.
8
+ - Patterns that depend on dynamic object mutation, loose shape matching, or reflective syntax are often rejected.
9
+ - Patterns based on `Record<string, T>`, arbitrary indexes, or namespace objects often need explicit ArkTS models.
10
+
11
+ Reference:
12
+ - Guide: `docs/ArkTS-Language-Guide/09-Migration-Guide/01-TypeScript-to-ArkTS/typescript-to-arkts-migration-guide.md`
13
+ - Linter summary: overview section
14
+
15
+ ## Prefer named types over inline shapes
16
+
17
+ TypeScript style:
18
+
19
+ ```ts
20
+ function printPoint(point: { x: number; y: number }): void {}
21
+ ```
22
+
23
+ ArkTS style:
24
+
25
+ ```ts
26
+ interface PointLike {
27
+ x: number
28
+ y: number
29
+ }
30
+
31
+ function printPoint(point: PointLike): void {}
32
+ ```
33
+
34
+ Reference:
35
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/interfaces.md`
36
+
37
+ ## Prefer declarations over expressions
38
+
39
+ - Rewrite function expressions to arrow functions when the function is used as a value.
40
+ - Rewrite class expressions to named class declarations.
41
+ - Move nested function declarations to top-level declarations, class methods, or arrow-function values.
42
+
43
+ Reference:
44
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/classes.md`
45
+ - Linter summary: function and class sections
46
+
47
+ ## Prefer explicit class and interface modeling
48
+
49
+ - TypeScript often treats classes as object shapes; ArkTS prefers constructor-based initialization and declared members.
50
+ - TypeScript often relies on structural typing; ArkTS narrows that style and expects explicit named contracts.
51
+ - TypeScript often uses `Record` or indexed access for flexible maps; ArkTS authoring should prefer named interfaces/classes and direct property access when property names are known.
52
+
53
+ Reference:
54
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/classes.md`
55
+ - Guide: `docs/ArkTS-Language-Guide/02-Basic-Syntax/interfaces.md`
56
+ - Linter summary: structural typing restriction
57
+
58
+ ## Rewrite template strings
59
+
60
+ TypeScript style:
61
+
62
+ ```ts
63
+ const label: string = `Count: ${count}`
64
+ ```
65
+
66
+ ArkTS style:
67
+
68
+ ```ts
69
+ const label: string = "Count: " + count.toString()
70
+ ```
71
+
72
+ Reference:
73
+ - Linter summary: syntax restriction section
74
+
75
+ ## Rewrite namespace-as-value patterns
76
+
77
+ TypeScript style:
78
+
79
+ ```ts
80
+ const api = common
81
+ api.doWork()
82
+ ```
83
+
84
+ ArkTS style:
85
+
86
+ ```ts
87
+ common.doWork()
88
+ ```
89
+
90
+ If the code needs a runtime object, define that object explicitly instead of using a namespace as the value.
91
+
92
+ Reference:
93
+ - Linter summary: namespace section
94
+
95
+ ## Remove unsupported or narrowed syntax
96
+
97
+ Common rewrites:
98
+
99
+ - `var` -> `let` or `const`
100
+ - destructuring declaration -> explicit local bindings
101
+ - `value as T` -> typed variable, typed function return, constructor, or explicit conversion
102
+ - `` `${value}` `` -> string concatenation with explicit conversion
103
+ - `delete obj.x` -> construct the desired value without runtime property deletion
104
+ - `catch (err: Error)` -> `catch (err)`
105
+ - `type T = typeof Foo` -> use the explicit type you need instead of a type query
106
+
107
+ Reference:
108
+ - Linter summary: declaration, operator, and statement sections