Arkts Static Spec logo

Arkts Static Spec

Organization
openharmonyinsight
arkts-static-spec

ArkTS static language specification reference for OpenHarmony. Use this skill when reading or writing ArkTS (.ets), explaining ArkTS type-system and static-semantics rules, validating code against the ArkTS spec, investigating ArkTS compile-time behavior, or comparing ArkTS with TypeScript migration guidance.

Overview

Publisheropenharmonyinsight
Repositoryopenharmony-skills
Skill namearkts-static-spec
Stars
36
Forks
7
Bundled files
28
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 28 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by openharmonyinsight on GitHub. Read the source before you install it.

Installation

Install the Arkts Static Spec AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/arkts-static-spec
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openharmonyinsight/openharmony-skills.git /tmp/openharmony-skills
mkdir -p .claude/skills
cp -r /tmp/openharmony-skills/skills/arkts-static-spec .claude/skills/arkts-static-spec
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Arkts Static Spec in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Arkts Static Spec on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Arkts Static Spec is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

ArkTS Static Language Specification

Complete reference for the ArkTS programming language, including official specification and TypeScript migration guide.

⚠️ 使用原则(重要)

在使用本 skill 回答问题时,必须严格遵守以下原则:

  1. 严格按照 skill 文档内容回答

    • 所有回答必须基于 spec/ 和 cookbook/ 目录下的文档内容
    • 不添加文档之外的假设或推断
  2. 明确标注文档未说明的内容

    • 如果 skill 文档中没有明确说明某个特性,必须在回答中标注:
      • "⚠️ skill 文档未明确说明,待使用者自行确认"
    • 不要基于 TypeScript 或其他语言的特性进行假设
  3. 将 ArkTS 视为独立的静态语言

    • ArkTS 是一个独立的静态语言,不是 TypeScript 的超集
    • 不要假设 TypeScript 的特性在 ArkTS 中都支持
    • 以 ArkTS 官方规范为准,不以 TypeScript 语法为准

目录结构

本技能分为两个主要部分:

arkts-static-spec/
├── spec/              # ArkTS 语言规范
│   ├── types.md       # 类型系统
│   ├── classes.md     # 类声明
│   ├── expressions.md # 表达式和运算符
│   ├── statements.md  # 语句和控制流
│   ├── generics.md    # 泛型
│   ├── annotations.md # 注解和装饰器
│   ├── modules.md     # 模块系统
│   ├── lexical.md     # 词法结构
│   ├── names.md       # 声明和作用域
│   ├── conversions.md # 类型转换
│   ├── interfaces.md  # 接口
│   ├── enums.md       # 枚举
│   ├── errors.md      # 错误处理
│   ├── concurrency.md # 并发和异步
│   ├── stdlib.md      # 标准库
│   └── experimental.md# 实验性特性
│
└── cookbook/          # TypeScript 迁移指南
    ├── index.md       # 迁移指南总览
    ├── recipes.md     # 详细迁移食谱(144+ 项)
    └── compatibility.md # TypeScript vs ArkTS 兼容性详情

第一部分:ArkTS 语言规范 (spec/)

官方 ArkTS 语言规范参考,按主题组织。

核心规范文件

文件内容适用场景
types.md类型系统、预定义类型查询类型、类型推断、默认值
classes.md类声明、访问修饰符、继承定义类、实现接口、继承
expressions.md运算符、优先级表达式求值、运算符使用
statements.md控制流、循环、try-catchif/else、for、while、异常处理
generics.md泛型类型和函数编写泛型代码、类型约束
annotations.md装饰器和元数据使用 @Decorator
modules.mdImport/export、命名空间模块组织、导入导出
lexical.md标识符、关键字、字面量词法分析、语法规则
names.md声明、作用域、可见性变量作用域、命名冲突
conversions.md类型转换和上下文类型转换规则
interfaces.md接口声明和实现定义接口、实现契约
enums.md枚举类型使用枚举
errors.md错误处理和 try 语句异常处理、throw 语句
concurrency.mdAsync/await、TaskPool异步编程、并发
stdlib.md标准库 API内置对象和函数
experimental.md实验性特性FixedArray、char、函数重载等

第二部分:TypeScript 迁移指南 (cookbook/)

从 TypeScript 迁移到 ArkTS 的完整指南,包含 144+ 个详细迁移食谱和兼容性说明。

迁移指南文件

文件内容适用场景
index.md迁移指南总览了解迁移原因、设计原则、快速入门
recipes.md144+ 详细迁移食谱查询具体语法如何转换、常见问题解决
compatibility.mdTypeScript vs ArkTS 兼容性详情了解行为差异、数值语义、数组赋值等

快速开始

ArkTS 类型注解

typescript
let num: number = 42
const str: string = "hello"
let arr: number[] = [1, 2, 3]

ArkTS 类声明

typescript
class Person {
  private name: string
  public age: number

  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }

  public introduce(): string {
    return `I'm ${this.name}, ${this.age} years old`
  }
}

泛型函数

typescript
function identity<T>(value: T): T {
  return value
}

let num = identity<number>(42)
let str = identity<string>("hello")

异步函数

typescript
async function fetchData(): Promise<string> {
  const response = await fetch("https://example.com")
  return await response.text()
}

类型系统速查

预定义类型

分类类型说明
数值byte, short, int, long, float, double, number, bigint整数和浮点数
布尔booleantrue/false
字符char实验性,使用 c'A' 语法
字符串string文本数据
特殊void, null, undefined, never特殊用途
对象Object, object对象类型

注意:any 和 unknown 在 ArkTS 中不支持,必须使用显式类型。

类型运算符

  • 联合类型:T | U
  • 交集类型:T & U
  • 数组类型:T[] 或 Array<T>
  • 只读数组:readonly T[]

TypeScript 迁移速查

常见转换

TypeScriptArkTS说明
var x = 10let x: number = 10必须使用 let,明确类型
let x: anylet x: SpecificType禁止 any,使用具体类型
let {a, b} = objlet a = obj.a; let b = obj.b不支持对象解构
"prop" in objobj instanceof Class不支持 in 运算符
import m = require("mod")import * as m from "mod"使用 ES6 import

代码保持率

  • 完全支持(无需修改):90% - 97%
  • 部分支持(少量重构):约 2% - 8%
  • 不支持(需要重构):约 1%

查找指南

查询 ArkTS 语言规范

根据主题选择对应的规范文件:

查询 TypeScript 迁移问题


ArkTS vs TypeScript 关键差异

1. 静态类型强制执行

特性TypeScriptArkTS
静态类型可选强制
any 类型允许禁止
unknown 类型允许禁止
类型推断可选必须

2. 对象布局固定

特性TypeScriptArkTS
运行时添加属性允许(用 as any 绕过)禁止
删除属性允许(用 as any 绕过)禁止
对象布局可变固定

3. Null 安全

特性TypeScriptArkTS
null 赋值给非空类型可选模式下禁止强制禁止
undefined 作为值允许严格限制

4. 数值语义

typescript
let n = 1
console.log(n / 2)

// TypeScript: 0.5(浮点除法)
// ArkTS: 0(整数除法)

访问修饰符

修饰符可访问性
public任何地方(默认)
private仅类内部
protected类和子类
readonly初始化后不可变
static类级别,非实例级别

常见设计模式

单例模式

typescript
class Singleton {
  private static instance: Singleton
  private constructor() {}

  public static getInstance(): Singleton {
    if (!Singleton.instance) {
      Singleton.instance = new Singleton()
    }
    return Singleton.instance
  }
}

工厂模式

typescript
interface Product {
  operation(): string
}

class ConcreteProductA implements Product {
  operation(): string {
    return "Product A"
  }
}

class Factory {
  static create(type: string): Product {
    if (type === "A") {
      return new ConcreteProductA()
    }
    throw new Error("Unknown product type")
  }
}

为什么选择 ArkTS?

优势

  1. 程序稳定性

    • 严格类型检查,减少运行时错误
    • 编译时类型验证
    • 字段必须初始化
  2. 程序性能

    • 编译为字节码,执行更快
    • 消除运行时类型检查开销
    • 针对移动设备优化
  3. 代码可读性

    • 静态类型让代码意图清晰
    • 对象布局固定,行为可预测

迁移成本

  • 代码保持率:90% - 97%(遵循最佳实践)
  • 主要调整:移除 any、使用 let 代替 var
  • 学习曲线:TypeScript 开发者易于上手

控制流速查

if-else

typescript
if (condition) {
  // ...
} else {
  // ...
}

循环

typescript
// while 循环
while (condition) {
  // ...
}

// for 循环
for (let i: int = 0; i < 10; i++) {
  // ...
}

// for-of 循环
for (const item of array) {
  // ...
}

错误处理

typescript
try {
  // 可能抛出错误的代码
} catch (e: Error) {
  // 处理错误
} finally {
  // 清理(总是执行)
}

迁移检查清单

优先级 1:必须修复(ERROR 级别)

  • 替换所有 var 为 let
  • 移除所有 any / unknown 类型
  • 移除 Symbol() API 使用
  • 移除私有 # 标识符
  • 确保类型和命名空间名称唯一
  • 移除非标识符属性名
  • 移除调用签名和构造签名类型
  • 移除 in 运算符
  • 移除对象解构
  • 替换 require 为标准 import
  • 移除 export = 语法

优先级 2:代码改进建议(WARNING 级别)

  • 检查字段初始化
  • 审查对象属性访问模式
  • 确保类型安全

完整参考

  • ArkTS 语言规范:spec/
  • TypeScript 迁移指南:cookbook/
  • 原始规范文档:D:\arkcompiler\runtime_core\static_core\plugins\ets\doc\spec\
  • 原始 Cookbook:D:\arkcompiler\runtime_core\static_core\plugins\ets\doc\cookbook\

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Arkts Static Spec AI skill do?

ArkTS static language specification reference for OpenHarmony. Use this skill when reading or writing ArkTS (.ets), explaining ArkTS type-system and static-semantics rules, validating code against the ArkTS spec, investigating ArkTS compile-time behavior, or comparing ArkTS with TypeScript migration guidance.

Why use Arkts Static Spec on TypingMind?

Because you install it once and use it with any model. Arkts Static Spec is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Arkts Static Spec in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/arkts-static-spec. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Arkts Static Spec?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Arkts Static Spec?

As many as you like. As long as a model supports skills, you can use Arkts Static Spec with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Arkts Static Spec AI skill free?

It is published on GitHub by openharmonyinsight. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇