# ArkTS

**ArkTS** 是华为开发的一种静态类型编程语言，作为 [HarmonyOS](https://www.edgepedia.org/zh/harmonyos) 应用开发的首选主语言。它基于 [TypeScript](https://www.edgepedia.org/zh/typescript)，保留了 TypeScript 的大部分语法，并增加了更严格的编译期规则，以及面向 ArkUI 框架的声明式 UI 和状态管理特性。<sup>[1](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)</sup> ArkTS 源代码存储在 `.ets` 文件中，由 ArkCompiler 工具链编译为 ArkCompiler 字节码（`.abc` 文件），再由 ArkTS 运行时在设备上执行。<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup><sup> • </sup><sup>[3](https://github.com/openharmony/arkcompiler_ets_runtime/blob/master/docs/overview.md)</sup>

| 关键事实 | 详情 |
|---|---|
| 定位 | HarmonyOS 应用开发的首选主编程语言<sup>[1](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)</sup> |
| 基础 | TypeScript 的扩展；兼容 TS 与 JavaScript 生态<sup>[1](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)</sup> |
| 编译 | 编译为 ArkCompiler 字节码（.abc），而非 JavaScript<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup> |
| 自 API 10 起的静态规则 | 强制静态类型、运行时对象布局固定、运算符语义受限、不支持结构化类型<sup>[1](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)</sup> |
| 空安全 | 所有类型默认不可为空；可空值使用联合类型 `T \| null`<sup>[4](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/introduction-to-arkts)</sup> |
| 并发 | TaskPool（动态线程伸缩）与 Worker（最多 64 线程）；Sendable 对象用于跨实例引用传递<sup>[5](https://developer.huawei.com/consumer/en/doc/harmonyos-faqs-V14/faqs-arkts-28-V14)</sup><sup> • </sup><sup>[6](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-overview)</sup> |
| 数字类型 | 双精度 64 位 IEEE 754；精确整数范围仅为 -2^53+1 到 2^53-1<sup>[7](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/use-napi-basic-data-types-V14)</sup> |

## 华为为何限制 TypeScript

华为的迁移文档给出了偏离标准 TypeScript 的两个理由：程序稳定性和程序性能。<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup>

**稳定性。** 动态类型语言允许快速编写代码，但容易产生意外的运行时错误，例如从 undefined 值上读取属性。TypeScript 能在编译期捕获许多此类错误，但它允许宽松的类型标注，从而留下缺口。ArkTS 强制静态类型，以实现更严格的检查、减少运行时错误。一条具体规则是显式字段初始化：每个类字段都必须在声明时或构造函数中赋值，类似于 TypeScript 的 `strictPropertyInitialization` 模式，这样即使忘记调用 setter，也不会在运行时产生 undefined 字段。<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup>

**性能。** 标准 TypeScript 编译为 [JavaScript](https://www.edgepedia.org/zh/javascript)，因此继承了 JavaScript 的运行时类型检查——引擎可以优化这些检查，但永远无法消除。由于 ArkTS 强制静态类型，它改为编译为 Ark 字节码，文档称其执行更快、也更易于进一步优化。<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup> ArkCompiler 运行时提供解释器、提前编译（AOT）编译器和实验性 JIT 编译器，以及使用并发标记和部分内存压缩的垃圾回收器（CMS-GC 和 Partial-Compressing-GC）。<sup>[3](https://github.com/openharmony/arkcompiler_ets_runtime/blob/master/docs/overview.md)</sup><sup> • </sup><sup>[8](https://developer.huawei.com/consumer/cn/doc/HarmonyOS-Guides/arkts-runtime-overview)</sup>

## 与标准 TypeScript 的差异

自 API 版本 10 起，ArkTS 以四种有文档记载的方式加强静态检查：强制使用静态类型，使所有类型在编译期已知；禁止运行时改变对象布局，使对象形状在程序执行期间保持固定；限制运算符语义，例如将一元加号运算符限定于数字；不支持结构化类型——即 TypeScript 中允许任何具有匹配成员的对象满足接口的特性。华为表示，后续版本可能根据需求和反馈支持结构化类型。<sup>[1](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)</sup>

迁移规则还禁止或限制特定的 TypeScript 构造：`any` 和 `unknown` 必须替换为具体类型，对象字面量必须带有声明类型，不能通过索引访问属性（`obj['field']`），接口不能声明构造函数签名。<sup>[9](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-more-cases-V5)</sup><sup> • </sup><sup>[10](https://developer.huawei.com/consumer/cn/forum/topic/0207214322291341073?fid=0109140870620153026)</sup> 空安全比 TypeScript 可选的 `strictNullChecks` 标志更严格：在 ArkTS 中它始终开启，因此 `let x: number = null` 是编译期错误，可空变量必须声明为 `T | null`。后缀非空断言运算符 `!` 和空值合并运算符 `??` 可用于处理可空值。<sup>[4](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/introduction-to-arkts)</sup>

应用环境本身也受到限制：强制启用严格模式（`use strict`），禁止 `eval()`、`with() {}` 以及从字符串创建函数。API 版本 11 的 HarmonyOS SDK 使用 TypeScript 4.9.5，target 字段为 `es2017`，因此 TS/JS 开发可以使用 ECMA2017+ 语法。<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup>

## 使用 ArkUI 进行 UI 开发

ArkTS 是 ArkUI 声明式 UI 框架的语言。组件通过声明式地组合和扩展来描述：组件实例化时不使用 `new` 关键字，属性和事件通过链式方法调用附加，子组件放置在尾随闭包内。事件处理器使用箭头函数语法 `() => {...}`，使函数绑定到组件；不允许使用 `this` 引用不明确的匿名函数。<sup>[11](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/arkts-declarative-ui-description)</sup>

**状态管理**通过装饰器将数据与 UI 关联。在状态管理 V1 中，组件内部装饰器包括 `@State`、`@Prop`、`@Link`、`@ObjectLink`、`@Provide` 和 `@Consume`；V2 引入 `@Local`、`@Param`、`@Event`、`@ObservedV2` 和 `@Trace`，遵循模型-视图-视图模型（MVVM）架构，数据变化自动更新 UI。<sup>[12](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-v5/arkts-custom-component-mixed-scenarios-V5)</sup><sup> • </sup><sup>[13](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-mvvm-v2-V14)</sup> 例如，`@Prop` 装饰器建立从父组件状态变量到子组件的单向同步，子组件中的变化不会回传。<sup>[14](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/arkts-prop-V13)</sup> `$$` 运算符向内置组件提供变量的引用以实现双向同步，自 API 版本 12 起，`!!` 语法在状态管理 V2 中提供统一的双向绑定。<sup>[15](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V13/arkts-two-way-sync-V13)</sup><sup> • </sup><sup>[16](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-new-binding-V5)</sup>

**渲染控制**包括使用 `if`/`else` 的条件渲染、对数据源的 `ForEach` 迭代，以及按需迭代的 `LazyForEach`。<sup>[1](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)</sup>

## 并发与共享数据

ArkTS 增强了 TS/JS 之外的并发能力，提供两个 API：TaskPool 根据硬件状况和任务负载动态调整线程数，并优先调度高优先级任务；Worker 支持有限数量的长生命周期线程，每个应用最多 64 个 Worker 线程。两种机制相互独立，因此达到 Worker 上限不会影响 TaskPool。<sup>[5](https://developer.huawei.com/consumer/en/doc/harmonyos-faqs-V14/faqs-arkts-28-V14)</sup> Sendable 概念支持在并发实例之间按引用传递对象，以提高通信性能。<sup>[6](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-overview)</sup> 对于共享数据，`@arkts.collections` 模块提供 Array、Map、Set、TypedArray 和 ArrayBuffer 容器，默认在并发任务之间按引用传递；它们不是线程安全的，使用快速失败机制，在并发结构性修改时抛出异常，因此安全修改需要异步锁。<sup>[17](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-collections-introduction-V14)</sup>

## 文件类型与互操作

ArkTS 代码位于 `.ets` 文件中，而纯 TypeScript 使用 `.ts` 文件。ArkTS 基于 TS 语法开发并与之兼容，华为建议 UI 相关内容使用 ArkTS，业务逻辑使用 TS。`.ts` 文件不能调用 `.ets` 文件中定义的方法，但 `.ets` 文件可以使用 ES6 `import`/`export` 语法导入并调用 `.ts` 文件导出的方法。<sup>[18](https://developer.huawei.com/consumer/en/doc/harmonyos-faqs-V14/faqs-arkts-53-V14)</sup> 在 API 版本 10 之前，`.ets` 文件完全采用标准 TS 语法；自 API 版本 10 起，SDK 在编译期验证 ArkTS 语法，当 `compatibleSdkVersion` 为 10 或更高时，将问题报告为阻止编译的错误，否则报告为警告。<sup>[2](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)</sup> 与 C/C++ 的互操作通过 Node-API 提供；ArkTS 的 Number 类型是双精度 64 位 [IEEE 754](https://www.edgepedia.org/zh/ieee-754) 值，超出 -2^53+1 到 2^53-1 范围的整数必须通过 Node-API BigInt 接口处理。<sup>[7](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/use-napi-basic-data-types-V14)</sup>

## 工具链与生态定位

开发使用 DevEco Studio，它支持预览 ArkUI 页面和组件；页面用 `@Entry` 装饰器标记，组件用 `@Preview` 标记，每个源文件最多可有 10 个 `@Preview` 装饰器。<sup>[19](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-previewer-arkui-V5)</sup> 语言规范将 ArkTS 描述为一种多范式语言，支持命令式、面向对象、函数式和泛型编程，具有基于类的单继承、接口和泛型，并指出其生态包括编译器、标准库，以及从 TypeScript 和 Java 半自动迁移的工具。<sup>[20](https://yoyocat.github.io/ArkTSSpec/1_intro.html)</sup>

由于 ArkTS 是一门年轻的领域特定语言，大语言模型对它的处理不如主流语言可靠。一项 2026 年针对 300 个 ArkTS 提示词的评估发现，21 个模型的 Pass@1 率普遍偏低，其中 [DeepSeek-R1](https://www.edgepedia.org/zh/deepseek-r1) 得分最高；报告称，添加一个精简的 ArkTS 示例加上一步编译器引导的修复，可将 Pass@1 从 23.3% 提升到 36.7%；常见失败包括缺少导入、泛型边界错误以及响应式状态形式误用。<sup>[21](https://link.springer.com/article/10.1007/s10664-026-10844-0)</sup> ArkRepoBench 是一个仓库级补全基准，包含来自 20 个官方 HarmonyOS 仓库的 7,519 个样本，其发现 ArkTS 补全在其设置下始终不如主流语言，而提供 HarmonyOS API 文档则能持续改善结果。<sup>[22](https://aclanthology.org/2026.findings-acl.969/)</sup>

## References

1. [Getting Started with ArkTS, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-get-started-V5)
2. [ArkTS Migration Background, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-migration-background-V14)
3. [ArkCompiler eTS Runtime Overview, OpenHarmony GitHub](https://github.com/openharmony/arkcompiler_ets_runtime/blob/master/docs/overview.md)
4. [ArkTS语言介绍 (Introduction to ArkTS), Huawei Developer](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/introduction-to-arkts)
5. [Do Worker and TaskPool limit the number of threads?, Huawei Developer FAQ](https://developer.huawei.com/consumer/en/doc/harmonyos-faqs-V14/faqs-arkts-28-V14)
6. [ArkTS简介 (ArkTS Overview), Huawei Developer](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-overview)
7. [Working with Basic Data Types Using Node-API, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/use-napi-basic-data-types-V14)
8. [ArkTS运行时概述 (ArkTS Runtime Overview), Huawei Developer](https://developer.huawei.com/consumer/cn/doc/HarmonyOS-Guides/arkts-runtime-overview)
9. [适配指导案例 (TypeScript to ArkTS Adaptation Cases), Huawei Developer](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-more-cases-V5)
10. [关于鸿蒙官方文档中的方法签名规则问题, Huawei Developer Forum](https://developer.huawei.com/consumer/cn/forum/topic/0207214322291341073?fid=0109140870620153026)
11. [Declarative UI Description, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/arkts-declarative-ui-description)
12. [自定义组件混合场景 (Custom Component Mixed Scenarios), Huawei Developer](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-v5/arkts-custom-component-mixed-scenarios-V5)
13. [MVVM (V2), Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-mvvm-v2-V14)
14. [@Prop装饰器：父子单向同步, Huawei Developer](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/arkts-prop-V13)
15. [$$ Syntax: Two-Way Synchronization of Built-in Components, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V13/arkts-two-way-sync-V13)
16. [!! Syntax: Two-Way Binding, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/arkts-new-binding-V5)
17. [Shared Container (ArkTS Collections), Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/arkts-collections-introduction-V14)
18. [What are the differences between .ets and .ts files?, Huawei Developer FAQ](https://developer.huawei.com/consumer/en/doc/harmonyos-faqs-V14/faqs-arkts-53-V14)
19. [Previewing an ArkUI Page or Component, Huawei Developer](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-previewer-arkui-V5)
20. [ArkTS Specification 1.1.0, Introduction](https://yoyocat.github.io/ArkTSSpec/1_intro.html)
21. [ArkTS code generation: A comprehensive evaluation with large language models, Empirical Software Engineering (2026)](https://link.springer.com/article/10.1007/s10664-026-10844-0)
22. [ArkRepoBench: A Repository-Level Code Completion Benchmark for HarmonyOS Development, Findings of ACL 2026](https://aclanthology.org/2026.findings-acl.969/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages › C-family and imperative languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/arkts

English original: https://www.edgepedia.org/arkts
