arkts-syntax-assistant by summerkaze/skill-arkts-syntax-assistant
npx skills add https://github.com/summerkaze/skill-arkts-syntax-assistant --skill arkts-syntax-assistantArkTS 是 OpenHarmony 应用程序的默认开发语言。它基于 TypeScript,并增强了静态类型,以提高程序的稳定性和性能。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 迁移背景 | references/en/arkts-migration-background.md |
| 性能 | references/en/arkts-high-performance-programming.md |
| 更多案例 | references/en/arkts-more-cases.md |
User Question -> Identify Question Type -> Consult Documentation -> Provide Code Example
常见语法问题:
let/constIdentify TS Code -> Check Incompatible Features -> Consult Migration Rules -> Provide ArkTS Alternative
关键迁移规则速查:
| TypeScript | ArkTS 替代方案 |
|---|---|
var x | let x |
any/unknown | 具体类型 |
{n: 42} 对象字面量 | 先定义类/接口 |
[index: T]: U 索引签名 | Record<T, U> |
A & B 交叉类型 | interface C extends A, B |
function(){} 函数表达式 | () => {} 箭头函数 |
<Type>value 类型断言 | value as Type |
解构 [a, b] = arr | 单独访问 arr[0], arr[1] |
for..in | for 循环或 for..of |
| 构造函数参数属性 | 显式字段声明 |
Analyze Code -> Identify Performance Issues -> Consult Optimization Guide -> Provide Solutions
高性能编程要点:
const;避免混合整数和浮点数Get Error Message -> Search Migration Rules -> Find Related Case -> Provide Fix
// 错误
let data = JSON.parse(str);
// 正确
let data: Record<string, Object> = JSON.parse(str);
// TypeScript 语法 (ArkTS 不支持)
type Person = { name: string, age: number }
// ArkTS 语法
interface Person {
name: string;
age: number;
}
// 使用对象字面量
let p: Person = { name: 'John', age: 25 };
// 错误
globalThis.value = 'xxx';
// 使用单例模式
export class GlobalContext {
private constructor() {}
private static instance: GlobalContext;
private _objects = new Map<string, Object>();
public static getContext(): GlobalContext {
if (!GlobalContext.instance) {
GlobalContext.instance = new GlobalContext();
}
return GlobalContext.instance;
}
getObject(key: string): Object | undefined {
return this._objects.get(key);
}
setObject(key: string, value: Object): void {
this._objects.set(key, value);
}
}
// 错误
try {} catch (e: BusinessError) {}
// 正确
try {} catch (error) {
let e: BusinessError = error as BusinessError;
}
// TypeScript 索引签名
function foo(data: { [key: string]: string }) {}
// ArkTS Record
function foo(data: Record<string, string>) {}
// 使用示例
let map: Record<string, number> = {
'John': 25,
'Mary': 21,
};
// TypeScript 构造函数签名
type ControllerCtor = {
new (value: string): Controller;
}
// ArkTS 工厂函数
type ControllerFactory = () => Controller;
class Menu {
createController: ControllerFactory = () => {
return new Controller('default');
}
}
以下 API 在 ArkTS 中被禁止使用:
eval__proto__、defineProperty、freeze、getPrototypeOf 等apply、construct、defineProperty 等scripts 目录提供了 ArkTS 项目的快速编译脚本(包括依赖安装):
| 平台 | 脚本 | 用途 |
|---|---|---|
| macOS/Linux | scripts/run.sh | 执行 ohpm install + hvigorw assembleApp |
| Windows | scripts/run.ps1 | 执行 ohpm install + hvigorw assembleApp |
使用方法:
# macOS/Linux
bash scripts/run.sh
# Windows PowerShell
.\scripts\run.ps1
脚本执行步骤:
ohpm install --all)hvigorw assembleApp)重要:当此技能生成 ArkTS 代码时,必须遵循以下工作流程:
编译验证:生成代码后,必须使用构建脚本编译项目:
bash scripts/run.sh.\scripts\run.ps1重试策略:如果编译失败:
用户干预:在 3 次编译尝试失败后,使用 AskUserQuestion:
Question: Compilation failed after 3 attempts. How would you like to proceed?
Options:
- Continue retrying (attempt another fix)
- Manual intervention (I'll wait for your guidance)
- Skip compilation (proceed without verification)
错误报告:当发生失败时,始终显示完整的编译错误输出。
MIT 许可证 - 参见 LICENSE.txt
每周安装量
182
代码仓库
GitHub Stars
35
首次出现
Jan 29, 2026
安全审计
安装于
opencode168
codex161
gemini-cli157
github-copilot150
kimi-cli148
amp148
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装