summerkaze/skill-arkts-syntax-assistant
Overview
This skill provides ArkTS syntax guidance, TypeScript-to-ArkTS migration help, and performance optimization tips for HarmonyOS/OpenHarmony development. It focuses on practical code examples, common compile fixes, and language-specific restrictions that affect app stability and runtime performance. Use it to resolve compile errors, improve performance, and convert TS code to ArkTS idioms.
How this skill works
The assistant inspects .ets files, ArkTS keywords, @ohos imports, and HarmonyOS context to identify syntax issues, incompatible TypeScript patterns, or performance anti-patterns. It returns concise explanations, side-by-side correct vs incorrect code examples, recommended ArkTS alternatives, and links to relevant reference documents. For generated code it enforces a compile-verify workflow and reports full build output if compilation fails.
When to use it
- Converting TypeScript codebases to ArkTS for HarmonyOS/OpenHarmony
- Fixing ArkTS compile errors or type mismatches in .ets files
- Optimizing hot paths, loops, and array usage for performance
- Designing components, state management, and lifecycle in ArkTS
- Replacing unsupported JS/TS features with ArkTS-safe patterns
Best practices
- Prefer explicit types and const for invariants to improve static checks and performance
- Avoid dynamic object layout; declare interfaces or classes before using object literals
- Use Record<K,V> instead of index signatures and avoid union-typed arrays for numeric-heavy data
- Extract loop invariants, avoid closures in hot loops, and use TypedArray for numeric arrays
- Handle catch variables using untyped catch then assert specific error types with as
Example use cases
- Migrate a React/TS component to an ArkTS .ets component with explicit props and state management
- Resolve JSON.parse typing and map the result to Record<string, Object> to prevent compile errors
- Refactor a performance-critical loop: eliminate optional parameters and use local temporaries for invariants
- Replace globalThis usage with a singleton GlobalContext pattern for shared data
- Translate a TypeScript constructor-signature pattern to an ArkTS factory function
FAQ
ArkTS requires declared interfaces or classes for object shapes; define an interface and then assign an object literal of that interface type.
What is the recommended way to type JSON.parse results?
Declare a target type such as Record<string, Object> or a specific interface and assign JSON.parse(...) to that typed variable to avoid implicit any issues.
Which standard APIs are prohibited in ArkTS and why?
APIs like eval, Proxy handlers, and many Reflect/Object prototype operations are disallowed to preserve static layout, performance, and platform safety; use supported design patterns or explicit APIs instead.