Skip to content
Back to search

arkts-syntax-assistant

ArkTS syntax, migration, and optimization guide for HarmonyOS/OpenHarmony development. Triggers on: .ets files, ArkTS keywords, HarmonyOS/OpenHarmony context, @ohos packages. Help with syntax reference, TypeScript migration, performance optimization, compile errors, state management, component development, and language-specific questions.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/summerkaze--skill-arkts-syntax-assistant/badge.svg)](/listings/summerkaze--skill-arkts-syntax-assistant)

HTML

<a href="/listings/summerkaze--skill-arkts-syntax-assistant"><img src="/api/listings/summerkaze--skill-arkts-syntax-assistant/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

推荐方式:使用 npx skills add(一键安装)

npx skills add https://github.com/SummerKaze/skill-arkts-syntax-assistant.git

这是最简单快速的安装方式,会自动下载并配置技能。

方式一:通过 Release 安装

1. 访问 [Releases](https://github.com/SummerKaze/skill-arkts-syntax-assistant/releases) 页面 2. 下载最新版本的压缩包 3. 解压到 Claude Code 的技能目录

方式二:克隆仓库

cd ~/.claude/skills/
git clone https://github.com/SummerKaze/skill-arkts-syntax-assistant.git

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 282 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. ---
  2. name: arkts-syntax-assistant
  3. description: |-
  4. ArkTS syntax, migration, and optimization guide for HarmonyOS/OpenHarmony development.
  5. Triggers on: .ets files, ArkTS keywords, HarmonyOS/OpenHarmony context, @ohos packages.
  6. Help with syntax reference, TypeScript migration, performance optimization,
  7. compile errors, state management, component development, and language-specific questions.
  8. license: MIT
  9. tags:
  10. - arkts
  11. - harmonyos
  12. - typescript
  13. - migration
  14. - development
  15. - syntax
  16. ---
  17. # ArkTS Syntax Assistant
  18. [中文文档](SKILL.zh.md)
  19. ---
  20. ## Overview
  21. ArkTS is the default development language for OpenHarmony applications. It builds
  22. upon TypeScript with enhanced static typing to improve program stability and
  23. performance.
  24. ## Core Features
  25. - **Static Typing**: All types determined at compile time, reducing runtime checks
  26. - **No Dynamic Object Layout**: Object structure fixed at compile time, cannot be
  27. modified at runtime
  28. - **Restricted Operators**: Some operator behaviors are restricted to encourage
  29. clearer code semantics
  30. - **No Structural Typing**: Structural typing is currently not supported
  31. ## Reference Documentation
  32. | Scenario | Document |
  33. |----------|----------|
  34. | Syntax Learning | [references/en/introduction-to-arkts.md](references/en/introduction-to-arkts.md) |
  35. | Quick Overview | [references/en/arkts-get-started.md](references/en/arkts-get-started.md) |
  36. | TS Migration | [references/en/typescript-to-arkts-migration-guide.md](references/en/typescript-to-arkts-migration-guide.md) |
  37. | Migration Background | [references/en/arkts-migration-background.md](references/en/arkts-migration-background.md) |
  38. | Performance | [references/en/arkts-high-performance-programming.md](references/en/arkts-high-performance-programming.md) |
  39. | More Cases | [references/en/arkts-more-cases.md](references/en/arkts-more-cases.md) |
  40. ## Workflows
  41. ### 1. Syntax Questions
  42. ```
  43. User Question -> Identify Question Type -> Consult Documentation -> Provide Code Example
  44. ```
  45. **Common Syntax Questions**:
  46. - Variable declaration -> Use `let`/`const` with explicit type or inference
  47. - Function definition -> Supports optional parameters, defaults, rest parameters,
  48. arrow functions
  49. - Classes and interfaces -> Must initialize fields, supports inheritance and
  50. implementation
  51. - Generics -> Supports constraints and default values
  52. - Null safety -> Nullable types ((T | null)), non-null assertion ((!)), optional
  53. chaining ((?.))
  54. ### 2. TypeScript Migration
  55. ```
  56. Identify TS Code -> Check Incompatible Features -> Consult Migration Rules -> Provide ArkTS Alternative
  57. ```
  58. **Key Migration Rules Quick Reference**:
  59. | TypeScript | ArkTS Alternative |
  60. |------------|-------------------|
  61. | `var x` | `let x` |
  62. | `any`/`unknown` | Specific types |
  63. | `{n: 42}` object literal | Define class/interface first |
  64. | `[index: T]: U` index signature | `Record<T, U>` |
  65. | `A & B` intersection type | `interface C extends A, B` |
  66. | `function(){}` function expression | `() => {}` arrow function |
  67. | `<Type>value` type assertion | `value as Type` |
  68. | Destructuring `[a, b] = arr` | Individual access `arr[0]`, `arr[1]` |
  69. | `for..in` | `for` loop or `for..of` |
  70. | Constructor parameter properties | Explicit field declaration |
  71. ### 3. Performance Optimization
  72. ```
  73. Analyze Code -> Identify Performance Issues -> Consult Optimization Guide -> Provide Solutions
  74. ```
  75. **High-Performance Programming Key Points**:
  76. - **Declarations**: Use `const` for invariants; avoid mixing integer and float
  77. - **Loops**: Extract loop invariants; avoid numeric overflow
  78. - **Functions**: Parameter passing preferred over closures; avoid optional
  79. parameters
  80. - **Arrays**: Use TypedArray for numeric values; avoid sparse arrays and union
  81. type arrays
  82. - **Exceptions**: Avoid throwing in loops; use return values instead
  83. ### 4. Compile Error Resolution
  84. ```
  85. Get Error Message -> Search Migration Rules -> Find Related Case -> Provide Fix
  86. ```
  87. ## Common Questions
  88. ### Q: How to handle JSON.parse return value?
  89. ```typescript
  90. // Error
  91. let data = JSON.parse(str);
  92. // Correct
  93. let data: Record<string, Object> = JSON.parse(str);
  94. ```
  95. ### Q: How to define object types?
  96. ```typescript
  97. // TypeScript syntax (not supported in ArkTS)
  98. type Person = { name: string, age: number }
  99. // ArkTS syntax
  100. interface Person {
  101. name: string;
  102. age: number;
  103. }
  104. // Using object literal
  105. let p: Person = { name: 'John', age: 25 };
  106. ```
  107. ### Q: How to replace globalThis?
  108. ```typescript
  109. // Error
  110. globalThis.value = 'xxx';
  111. // Use singleton pattern
  112. export class GlobalContext {
  113. private constructor() {}
  114. private static instance: GlobalContext;
  115. private _objects = new Map<string, Object>();
  116. public static getContext(): GlobalContext {
  117. if (!GlobalContext.instance) {
  118. GlobalContext.instance = new GlobalContext();
  119. }
  120. return GlobalContext.instance;
  121. }
  122. getObject(key: string): Object | undefined {
  123. return this._objects.get(key);
  124. }
  125. setObject(key: string, value: Object): void {
  126. this._objects.set(key, value);
  127. }
  128. }
  129. ```
  130. ### Q: How to handle error types in catch?
  131. ```typescript
  132. // Error
  133. try {} catch (e: BusinessError) {}
  134. // Correct
  135. try {} catch (error) {
  136. let e: BusinessError = error as BusinessError;
  137. }
  138. ```
  139. ### Q: How to use Record type?
  140. ```typescript
  141. // TypeScript index signature
  142. function foo(data: { [key: string]: string }) {}
  143. // ArkTS Record
  144. function foo(data: Record<string, string>) {}
  145. // Usage example
  146. let map: Record<string, number> = {
  147. 'John': 25,
  148. 'Mary': 21,
  149. };
  150. ```
  151. ### Q: How to replace constructor signatures with factory functions?
  152. ```typescript
  153. // TypeScript constructor signature
  154. type ControllerCtor = {
  155. new (value: string): Controller;
  156. }
  157. // ArkTS factory function
  158. type ControllerFactory = () => Controller;
  159. class Menu {
  160. createController: ControllerFactory = () => {
  161. return new Controller('default');
  162. }
  163. }
  164. ```
  165. ## Prohibited Standard Library APIs
  166. The following are prohibited in ArkTS:
  167. - **Global**: `eval`
  168. - **Object**: `__proto__`, `defineProperty`, `freeze`, `getPrototypeOf`, etc.
  169. - **Reflect**: `apply`, `construct`, `defineProperty`, etc.
  170. - **Proxy**: All handler methods
  171. ## Build Scripts
  172. The scripts directory provides quick compilation scripts for ArkTS projects
  173. (including dependency installation):
  174. | Platform | Script | Purpose |
  175. |----------|--------|---------|
  176. | macOS/Linux | `scripts/run.sh` | Execute `ohpm install` + `hvigorw assembleApp` |
  177. | Windows | `scripts/run.ps1` | Execute `ohpm install` + `hvigorw assembleApp` |
  178. Usage:
  179. ```bash
  180. # macOS/Linux
  181. bash scripts/run.sh
  182. # Windows PowerShell
  183. .\scripts\run.ps1
  184. ```
  185. Script execution steps:
  186. 1. Install dependencies (`ohpm install --all`)
  187. 2. Build project (`hvigorw assembleApp`)
  188. ## Mandatory Requirements
  189. **CRITICAL**: When this skill generates ArkTS code, the following workflow MUST be followed:
  190. 1. **Compilation Verification**: After generating code, you MUST compile the project using the build scripts:
  191. - macOS/Linux: `bash scripts/run.sh`
  192. - Windows: `.\scripts\run.ps1`
  193. 2. **Retry Strategy**: If compilation fails:
  194. - Analyze the error output
  195. - Fix the issue and retry compilation
  196. - Maximum of **3 compilation attempts**
  197. 3. **User Intervention**: After 3 failed compilation attempts, use `AskUserQuestion`:
  198. ```
  199. Question: Compilation failed after 3 attempts. How would you like to proceed?
  200. Options:
  201. - Continue retrying (attempt another fix)
  202. - Manual intervention (I'll wait for your guidance)
  203. - Skip compilation (proceed without verification)
  204. ```
  205. 4. **Error Reporting**: Always show the full compilation error output when failures occur.
  206. ## Answer Guidelines
  207. 1. **Prioritize code examples**: Show correct vs incorrect syntax comparison
  208. 2. **Reference official documentation**: For detailed explanations, guide users to
  209. consult corresponding documents in references/
  210. 3. **Explain reasons**: Explain why ArkTS has this restriction (performance,
  211. stability)
  212. 4. **Provide alternatives**: For unsupported features, provide feasible
  213. alternatives
  214. ## License
  215. MIT License - see [LICENSE.txt](LICENSE.txt)
README.md · README · 167 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <div align="center">
  2. # ArkTS Syntax Assistant
  3. [English](./README.en.md) | 简体中文
  4. ![GitHub License](https://img.shields.io/github/license/SummerKaze/skill-arkts-syntax-assistant?style=flat)&nbsp;
  5. ![GitHub Release](https://img.shields.io/github/v/release/SummerKaze/skill-arkts-syntax-assistant?style=flat)&nbsp;
  6. ![GitHub Repo stars](https://img.shields.io/github/stars/SummerKaze/skill-arkts-syntax-assistant?style=flat)&nbsp;
  7. </div>
  8. > ArkTS 语言学习与开发助手,提供语法参考、TypeScript 迁移指导和高性能编程实践
  9. 这是一个支持多平台的 ArkTS 语法助手技能,兼容 claude-code、opencode、cursor、trea 等 AI 编码助手。ArkTS 是 OpenHarmony 应用的默认开发语言,在 TypeScript 基础上做了静态类型强化,提升程序稳定性和性能。
  10. ## 功能特性
  11. - **语法学习**:涵盖 ArkTS 基础语法(声明、类型、函数、类、泛型、模块等)
  12. - **TypeScript 迁移**:详细的 TS 到 ArkTS 迁移指南,包括语法约束、类型系统差异、不兼容特性
  13. - **高性能编程**:内存优化、循环优化、数组处理、异常处理等最佳实践
  14. - **编译错误解决**:常见编译错误的诊断和修复方案
  15. - **代码示例**:丰富的对比示例,展示正确与错误写法
  16. ## 开发工具支持
  17. 这个技能可以帮助您的AI助手轻松编写ArkTS代码,但如果您也需要自己编写和修改代码,却对DevEco Studio缺少Tab补全功能感到困扰,欢迎在VSCode(及同类IDE)中安装ArkTS语言支持插件:
  18. <div align="center">
  19. ### Naily's ArkTS Support
  20. [![](https://img.shields.io/badge/VSCode-Plugin-informational?style=for-the-badge&logo=visual-studio-code&logoColor=white&color=007ACC)](https://marketplace.visualstudio.com/items?itemName=NailyZero.vscode-naily-ets)
  21. </div>
  22. > [!NOTE]
  23. > **[Naily's ArkTS Support](https://github.com/ohosvscode/arkTS)** 是一个为VSCode设计的ArkTS语言支持插件,提供了语法高亮、智能补全等功能,让开发者在VSCode中也能获得良好的ArkTS开发体验。
  24. ## 安装
  25. ### 推荐方式:使用 npx skills add(一键安装)
  26. ```bash
  27. npx skills add https://github.com/SummerKaze/skill-arkts-syntax-assistant.git
  28. ```
  29. 这是最简单快速的安装方式,会自动下载并配置技能。
  30. ### 方式一:通过 Release 安装
  31. 1. 访问 [Releases](https://github.com/SummerKaze/skill-arkts-syntax-assistant/releases) 页面
  32. 2. 下载最新版本的压缩包
  33. 3. 解压到 Claude Code 的技能目录
  34. ### 方式二:克隆仓库
  35. ```bash
  36. cd ~/.claude/skills/
  37. git clone https://github.com/SummerKaze/skill-arkts-syntax-assistant.git
  38. ```
  39. ## 文档导航
  40. 根据需求选择对应文档:
  41. | 场景 | 参考文档 |
  42. |------|----------|
  43. | **语法学习** | [references/zh/introduction-to-arkts.md](references/zh/introduction-to-arkts.md) |
  44. | **快速概览** | [references/zh/arkts-get-started.md](references/zh/arkts-get-started.md) |
  45. | **TS 迁移** | [references/zh/typescript-to-arkts-migration-guide.md](references/zh/typescript-to-arkts-migration-guide.md) |
  46. | **迁移背景** | [references/zh/arkts-migration-background.md](references/zh/arkts-migration-background.md) |
  47. | **性能优化** | [references/zh/arkts-high-performance-programming.md](references/zh/arkts-high-performance-programming.md) |
  48. | **更多案例** | [references/zh/arkts-more-cases.md](references/zh/arkts-more-cases.md) |
  49. ## 快速开始
  50. ### 使用技能
  51. 在 Claude Code 中,当你遇到以下问题时,此技能会自动激活:
  52. - 学习 ArkTS 基础语法
  53. - 从 TypeScript 迁移到 ArkTS
  54. - ArkTS 高性能编程优化
  55. - 解决 ArkTS 编译错误或运行时问题
  56. - HarmonyOS/OpenHarmony 应用开发中的语言相关问题
  57. ### 常见问题速查
  58. **Q: 如何处理 JSON.parse 返回值?**
  59. ```typescript
  60. // 错误
  61. let data = JSON.parse(str);
  62. // 正确
  63. let data: Record<string, Object> = JSON.parse(str);
  64. ```
  65. **Q: 如何定义对象类型?**
  66. ```typescript
  67. // TS 写法(ArkTS 不支持)
  68. type Person = { name: string, age: number }
  69. // ArkTS 写法
  70. interface Person {
  71. name: string;
  72. age: number;
  73. }
  74. ```
  75. **Q: TypeScript 到 ArkTS 迁移规则速查**
  76. | TS 写法 | ArkTS 替代 |
  77. |---------|-----------|
  78. | `var x` | `let x` |
  79. | `any`/`unknown` | 具体类型 |
  80. | `{n: 42}` 对象字面量 | 先定义 class/interface |
  81. | `[index: T]: U` 索引签名 | `Record<T, U>` |
  82. | `A & B` 交叉类型 | `interface C extends A, B` |
  83. | `<Type>value` 类型断言 | `value as Type` |
  84. | 解构赋值 `[a, b] = arr` | 逐个访问 `arr[0]`, `arr[1]` |
  85. | `for..in` | `for` 循环或 `for..of` |
  86. ## 编译脚本
  87. 项目提供快速编译脚本(包含依赖安装):
  88. | 平台 | 脚本 | 用途 |
  89. |------|------|------|
  90. | macOS/Linux | `scripts/run.sh` | 执行 `ohpm install` + `hvigorw assembleApp` |
  91. | Windows | `scripts/run.ps1` | 执行 `ohpm install` + `hvigorw assembleApp` |
  92. 使用方式:
  93. ```bash
  94. # macOS/Linux
  95. bash scripts/run.sh
  96. # Windows PowerShell
  97. .\scripts\run.ps1
  98. ```
  99. ## 核心特性
  100. - **强制静态类型**:编译时确定所有类型,减少运行时检查
  101. - **禁止动态对象布局**:对象结构在编译时固定,不可运行时修改
  102. - **限制运算符语义**:部分运算符行为受限,鼓励清晰代码
  103. - **不支持 Structural typing**:当前版本不支持结构化类型
  104. ## 禁止使用的 API
  105. 以下在 ArkTS 中禁止使用:
  106. - **全局**:`eval`
  107. - **Object**:`__proto__`、`defineProperty`、`freeze`、`getPrototypeOf` 等
  108. - **Reflect**:`apply`、`construct`、`defineProperty` 等
  109. - **Proxy**:所有 handler 方法
  110. ## Star History
  111. [![Star History Chart](https://api.star-history.com/svg?repos=SummerKaze/skill-arkts-syntax-assistant&type=date&legend=top-left)](https://www.star-history.com/#SummerKaze/skill-arkts-syntax-assistant&type=date&legend=top-left)
  112. ## License
  113. [MIT](./LICENSE.txt)
  114. Copyright (c) 2025 SummerKaze

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.