uts

Cursor rule "uts" from dcloudio/uni-app-x-ai-rules, covering uts 和 ts 的差异, 概述, 约束说明, 1. 核心语言特性 and 2. 类型系统相关.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/dcloudio/uni-app-x-ai-rules/uts
Clone the repo
git clone --depth 1 https://github.com/dcloudio/uni-app-x-ai-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 15,908 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.15908
Opus 5 $0.00000 $0.07954
Sonnet 5 $0.00000 $0.03182
Haiku 4.5 $0.00000 $0.01591

Measured today against content hash d1c1db442d00, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

uts scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/uts.mdc · 2,462 lines

How it starts

The opening of the file, as written. The whole thing — 2,462 lines — stays where its author put it; the contents beside it link to each section on GitHub.

uts 和 ts 的差异

ts 虽然有类型,但类型要求不严格。而 uts 为了编译为原生语言,是完全的强类型。

另外为了确保跨平台、高性能,uts 通过规范约束了 ts 中过于灵活而影响开发正确性或者给运行时带来不必要额外开销的特性。

本文罗列了在 uts 跨端开发时限制的 ts 特性,并提供了重构代码的建议。

uni-app x下uts编译器目前已知的一些问题

uni-app x下部分运行错误的说明

概述

强制使用静态类型

静态类型是 uts 最重要的特性之一。如果程序采用静态类型,即所有类型在编译时都是已知的,那么开发者就能够容易理解代码中使用了哪些数据结构。 同时,由于所有类型在程序实际运行前都是已知的,编译器可以提前验证代码的正确性,从而可以减少运行时的类型检查,有助于提升性能。

基于上述考虑,uts 中的 any 类型与 ts 中的 any 并不一样,它是一个根据目标平台自动适配的跨端类型,通常用于表示"任意的非空类型", 在使用时仍需类型转换后才能访问具体类型的方法和属性。

不支持结构化类型系统

结构化类型系统(structural typing)是 ts 的一个特性,它意味着类型的兼容性和等价性是基于类型的结构(即它们的属性和方法); 而在跨端开发时,uts 采用名义类型系统(nominal typing),类型兼容性检查基于类型名称和显式的继承/实现关系。 即使两个类型具有完全相同的结构,如果没有显式的继承/实现关系,它们也不能互相赋值。 这与 Kotlin 、Swift 、ArkTS 等静态语言的类型系统保持一致,有助于确保类型安全和代码的可维护性。

约束说明

1. 核心语言特性

不支持 undefined @uts110111119

级别: 错误

错误码: UTS110111119

不支持 undefined。所有变量必须赋值初始化后才能使用。如果需要使用空,请使用 null。 undefined 在 ts 中有很多场景,一个未初始化赋值的变量、一个未传入的方法参数、对象上不存在的属性,都会返回 undefined。

描述 UTS-TS UTS-ArkTS UTS-Kotlin UTS-Swift
适用版本 4.75 4.75 4.75 4.75
约束状态 x x

TypeScript写法:

// TypeScript 可以使用 undefined
let value: string | undefined;
if (value == undefined) {
  console.log("未定义");
}

function test(param?: string) {
  if (param == undefined) {
    console.log("参数未传");
  }
}

UTS正确写法:

// UTS 使用 null 替代 undefined
let value: string | null = null; //必须先赋值后使用,哪怕赋值为null。否则Android平台会报编译错误:error: Variable 'value' must be initialized‌
if (value == null) {
  console.log("未定义");
}

function test(param: string | null) {
  if (param == null) {
    console.log("参数未传");
  }
}
条件语句必须使用布尔类型 @uts110111120

级别: 错误

错误码: UTS110111120

所有条件语句(if、while、do-while、三元运算符、for 循环的条件部分)必须使用布尔类型作为条件。不支持 ts 中的隐式类型转换和 truthy/falsy 值。

描述 UTS-TS UTS-ArkTS UTS-Kotlin UTS-Swift
适用版本 4.75 4.75 4.75 4.75
约束状态 x x

Read the full file on GitHub · 2,462 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today First seen · 2,462 lines · 15,908 tokens per session scan A d1c1db442d00

Subscribe to this mod's changes

uts is a cursor rule published in the GitHub repository dcloudio/uni-app-x-ai-rules (30 stars, last pushed 3mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 15,908 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.