Agent skill
arkts-coding-standard
Enforces ArkTS strict typing rules and coding standards. Invoke when writing, analyzing, or correcting ArkTS code for HarmonyOS to ensure compliance.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/skills-imansmallapple-app-straypet
SKILL.md
ArkTS Coding Standards
This skill provides guidelines and validation for writing correct ArkTS code, focusing on strict typing and performance optimizations required for HarmonyOS development.
❌ Illegal / Discouraged Practices
The following patterns are forbidden or highly discouraged in ArkTS:
-
Any/Unknown Types:
typescriptlet x: any = 1; // ❌ Not allowed: `any` and `unknown` are forbidden. -
Object Literal Types:
typescripttype Inline = { value: number }; // ❌ Don't declare object-literal-based types. -
Fresh Object Literals (Untyped):
typescriptconst bad: Inline = { value: 1 }; // ❌ Fresh object literal without declared class/interface instance. -
Runtime Shape Changes:
typescriptbad.newProp = "later"; // ❌ Changing object shape (adding properties) at runtime is forbidden. -
Implicit Object Shapes:
typescriptconst obj = { value: 1, double() { return this.value + this.value; // ❌ `this` in a non-method context is disallowed. } }; // ❌ Even with an object literal, it must match an explicit class/interface. -
Type Mismatches:
typescriptbad.value = "7"; // ❌ Assigning string to a number-typed field fails. -
Implicit Coercion:
typescriptconsole.info(String(+bad.value)); // ❌ Unary `+` on a string for coercion is not permitted.
✅ Correct Practices
Use explicit types, classes, and safe conversions:
-
Explicit Numeric Parsing:
typescriptconst s: string = "7"; // Use explicit parsing methods instead of unary + const n: number = Number.parseInt(s); -
Classes and Interfaces: Always define explicit classes or interfaces for your data structures.
typescriptclass Doubler { value: number; constructor(value: number) { this.value = value; } } let obj = new Doubler(n);
Summary of Rules
- Static Typing: ArkTS is statically typed. Avoid dynamic features like
any. - Fixed Layout: Object layout is fixed at compile time. You cannot add/remove properties at runtime.
- Explicit Types: Define types explicitly using
classorinterface. Avoid anonymous object types. - Strict Safety: No implicit type coercion. Use standard library functions (e.g.,
Number.parseInt) for conversions.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?