aresbit/arkts-agent-skill
Overview
This skill provides comprehensive guidance on ArkTS, the statically-typed language extension used in HarmonyOS. It covers ArkTS syntax, type system, classes, functions, modules, and common language features to help developers write, debug, and learn ArkTS effectively.
How this skill works
The skill inspects ArkTS language constructs and references curated documentation sections such as language basics, type system, modules, and examples. It returns concise explanations, example patterns, and targeted guidance for syntax, type checks, class and function declarations, and error scenarios. Use the skill to retrieve code patterns, explanations of precedence and type operators, and practical snippets for common tasks.
When to use it
- Learning ArkTS fundamentals or onboarding to HarmonyOS development.
- Implementing or refactoring ArkTS code (types, classes, functions, modules).
- Debugging type errors, union/parentheses precedence, or compile-time type checks.
- Looking for concrete code patterns and quick reference examples.
- Preparing documentation, tutorials, or sample projects using ArkTS.
Best practices
- Prefer explicit type annotations for public APIs to improve readability and tooling support.
- Use parentheses to disambiguate composite types (arrays, unions, functions) when precedence matters.
- Model data with interfaces or classes for clearer keyof and typeReference behavior.
- Keep code examples small and focused to make compile-time errors easier to diagnose.
- Refer to the type system reference when using advanced features like keyof, union types, and generics.
Example use cases
- Show how to declare primitive and array types (boolean, number, Object, number[]).
- Explain precedence rules for union types and when parentheses are required.
- Demonstrate compile-time errors when a typeReference is not a class or interface.
- Provide small class examples showing fields, methods, and deriving keyof results.
- Offer module and import examples for structuring ArkTS projects in HarmonyOS.
FAQ
keyof reflects the property names of a class or interface. If you use it on a non-class/interface type or forget to expose members, you’ll get mismatches or compile-time errors.
When should I add parentheses around types?
Add parentheses when combining array, function, or union types where default precedence would change the intended structure. This avoids ambiguous types and compile errors.