arkts-skill
Installation
SKILL.md
ArkTS Skill
Use this skill to answer ArkTS language and type-system questions with spec-backed guidance.
Workflow
- Read the user problem and classify it as one of: syntax, type system, declarations, expressions/statements, classes/interfaces, or migration/compatibility.
- If the question is TypeScript-to-ArkTS migration related (especially "why not supported", including destructuring-assignment concerns), read
references/huawei-migration-priority.mdfirst. - For migration questions, use local files in
references/huawei-migration/*.mdfirst (local-first). - If local migration files are stale or insufficient, refresh them via
bash scripts/fetch_huawei_migration_refs.sh. - Search chapter files, then open only the matched files.
- Cite the exact section/topic names in your answer.
- Prefer minimal, directly compilable ArkTS examples.
- Keep recommendations simple and deterministic. If multiple options exist, present the simplest compliant one first.
Fast Search Patterns
Use targeted search on the chapter directory:
bash scripts/search_chapters.sh "union|narrow|keyof"rg -n "type|union|interface|class|function|async|decorator|generic" references/chaptersrg -n "assignment|narrow|overload|extends|implements|readonly|tuple|array|literal" references/chaptersrg -n "error|diagnostic|restriction|forbidden|not allowed|shall|must" references/chapters
Maintenance
- Rebuild chapter split from full OCR markdown:
python3 scripts/rebuild_chapters.py
- Refresh migration local references:
bash scripts/fetch_huawei_migration_refs.sh
- Keep
references/CHAPTER_INDEX.mdin sync with chapter files after rebuild.
Output Rules
- Prefer short explanations with one concrete fix.
- For compiler/type errors, include:
- Root cause in one sentence.
- Smallest valid code change.
- Why this matches spec behavior.
- For migration questions, produce a before/after snippet and list breaking points.
Compile Error Fix Playbook (Field-tested)
Use this checklist first when ArkTS build fails with strict diagnostics:
- Reproduce with CLI and capture exact diagnostics:
hvigorw assembleHap
- Map each error code to one direct rewrite, then recompile immediately.
Frequent Errors and Minimal Fixes
arkts-no-untyped-obj-literals:- Root cause: inline object literals in places where ArkTS requires explicit class/interface instances.
- Fix: replace
{ ... }values with class instances (new Xxx(...)) or strongly typed containers.
arkts-no-obj-literals-as-types:- Root cause: using object literal shape directly in type positions (for example inline
{ v: string, w: number }arrays). - Fix: extract a named
class/interface(for exampleWeightedItem) and use that type.
- Root cause: using object literal shape directly in type positions (for example inline
arkts-no-props-by-index:- Root cause: dynamic property indexing on fields like
obj[key]. - Fix: replace with
Map<K,V>(get/set) or explicitswitch/branch lookup.
- Root cause: dynamic property indexing on fields like
Practical Rewrite Patterns
Record<string, T>dictionaries with dynamic keys:- Prefer
Map<string, T>for mutable runtime lookup.
- Prefer
- i18n maps accessed by
I18N[lang][key]:- Replace with deterministic
switchfunction (t(key)), especially when key is runtime string.
- Replace with deterministic
- Bigram/follower tables as plain object literals:
- Replace with explicit lookup function
followersOf(ch)usingswitch.
- Replace with explicit lookup function
- Weak-key and weighted pools:
- Replace anonymous object items with named classes (
WeakKey,WeightedItem) to satisfy strict typing.
- Replace anonymous object items with named classes (
Validation Loop
- Change the smallest failing region.
- Re-run
hvigorw assembleHap. - Continue until only warnings remain.
- Report separately:
- Compile blockers fixed.
- Remaining warnings (deprecated APIs, throw-handling hints).
Reference
- Full OCR markdown:
arktsspecification_ocr_full.md - Chapter index:
references/CHAPTER_INDEX.md - OCR chapter files:
references/chapters/*.md - Migration-first references:
references/huawei-migration-priority.md - Migration local files:
references/huawei-migration/*.md
Related skills