---
url: /docs/guide/usage/linter/rules/vue/require-typed-ref.md
---

### 作用

要求 `ref` 和 `shallowRef` 函数具有明确的类型。

### 为什么这不好？

使用 TypeScript 时，可以通过 `noImplicitAny` 很容易地防止使用 `any`。
不幸的是，这条规则很容易被 Vue 的 `ref()` 函数绕过。
在没有泛型参数或初始值的情况下调用 `ref()` 函数，会导致 ref 的类型为 `Ref<any>`。

### 示例

以下是此规则的**错误**代码示例：

```typescript
const count = ref();
const name = shallowRef();
```

以下是此规则的**正确**代码示例：

```typescript
const count = ref<number>();
const a = ref(0);
```

## 如何使用

## 版本

此规则在 v1.17.0 中添加。

## 参考资料
