Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vue] 备忘录 #4

Open
NHZEX opened this issue Jul 22, 2024 · 1 comment
Open

[Vue] 备忘录 #4

NHZEX opened this issue Jul 22, 2024 · 1 comment

Comments

@NHZEX
Copy link
Owner

NHZEX commented Jul 22, 2024

No description provided.

@NHZEX
Copy link
Owner Author

NHZEX commented Jul 22, 2024

状况

错误1

定义const a = ref<T[]>([]),使用a.value.find(...)取出的值传递到函数function x(val: T)时会报告类似下方的错误内容:

 Two different types with this name exist, but they are unrelated.
        Types of property '...' are incompatible.
          Type '...' is not assignable to type 'Readonly<Ref<...>>'.

尝试可用的方法:

  1. const a = ref<T[]>([]) as Ref<T[]>,这样定义不需要修改接受传入值的地方。
  2. function x(val: UnwrapRef<T>),这样定义传入值时不在报错。

错误2

定义

const model = ref<T>(...)
const v1= computed<T>({
  get: () => model.value.xxx,
  set: value => {
    model.value.xxx= value;
  }
});

报告类似下方的错误内容:

# ERR-1
Vue: No overload matches this call.
Overload 1 of 2,
(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions | undefined): ComputedRef<T>
, gave the following error.
Overload 2 of 2,
(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions | undefined): WritableComputedRef<...>
, gave the following error.

# ERR-1
Vue: Parameter value implicitly has an any type.

尝试可用的方法:

const v1= computed<T>({
  get: () => model.value.xxx as T,
  set: value => {
    model.value.xxx = value as UnwrapRef<T>;
  }
});

可能相关资料

遇到类似问题

  • 使用ref包裹Map后,使用get取出值时遇到的类型错误也可能是这个。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant