-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[Type for Reactivity Transform] Add another type which indicates the value is deconstructed from defineProps
/ 为 响应性语法糖
添加一个可以标识变量是从 defineProps
中解构出来的类型
#6876
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
Comments
defineProps
defineProps
(中英双语)
defineProps
(中英双语)defineProps
/ 为 响应性语法糖
添加一个可以标识变量是从 defineProps
中解构出来的类型
According to RFC |
Here are the very prototype of definitions FYR: <script lang="ts" setup>
type Props = {
someArray: string[];
};
// ⬇️ ReactiveVariable<string[]>
const { someArray } = $defineProps<Props>();
// ⬇️ Ref<string[]>
const someArrayRef = $$(someArray);
</script> /// <reference types="vue/macros-global" />
import type { RefValue } from "vue/macros";
declare global {
function $defineProps<TypeProps>(): {
[Key in keyof TypeProps]: RefValue<TypeProps[Key]>;
};
}
export {}; |
Yeah seems like a valid fix. I'll keep an eye on it. |
I guess we should wait for Evan to make the decision on RFC. If there's any news, I'll ping you on this issue. |
Great, thanks. Guess I can learn a lot from the official fix. |
Same problem here. |
Implemented in Vue Macros. |
Thanks, that seems good. Will have a try later on. |
I think we should open this issue for official implementation tracking. |
#7986 |
What problem does this feature solve?
English:
It's related to #5976 and #6578, please have a look at these two issues first.
I've investigated the types of
Reactivity Transform
, and I think we need to add another type to indicate whether the value is deconstructed fromdefineProps
to solve the issue.Currently, we have no way to know whether the developer wants to:
Scenario 1: use
$$(Array)
for deconstructing an array, like inwatch
Scenario 2: use
$$(Array)
for keeping the reactivity of the array, like using on Arrays deconstructed fromdefineProps
So the current type in
macros.d.ts
cannot solve the issue, as we have no idea what is the purpose of using$$()
on an array.If we add this
It solves
Scenario 2
but breaksScenario 1
so it's not a valid fix. (It's only an issue about the type, the runtime compilation is working as expected)Maybe there's some other way to fix it, but I've tried my best.
中文:
请先阅读 #5976 和 #6578, 该提议和这两个问题有关.
我看了一下
响应性语法糖
的类型, 我觉得需要添加一个额外的类型来标识从defineProps()
解构出来的响应式变量 (以和其他的通过语法糖生成的响应式变量区分开) 来解决这个问题.目前我们没法知道一个开发者想通过哪种方式在
数组
上使用$$()
情况1: 通过
$$(Array)
解构数组, 让其中的每一个变量都保留响应式, 比如在watch
中情况2: 通过
$$(Array)
使从defineProps()
解构得到的数组保持响应性, 比如传递给需要接收Ref
的函数目前在
macros.d.ts
中的类型不足以解决问题, 因为我们不知道作用在数组上的$$()
到底是什么作用.如果加上这一个额外定义
它确实解决了
情况2
, 但同时破坏了情况1
, 所以这样是不对的. (仅仅是一个类型问题, 运行时编译一切正常)可能有其他方法能解决这个问题, 但是我尽力了. 太菜了😭
What does the proposed API look like?
English:
My ideal way is to add a type indicating that the value is deconstructed from
defineProps()
, e.g. inruntime-core.d.ts
and in
macros.d.ts
中文:
我理想的解决方法是添加一个可以标识某个变量是从
defineProps()
解构出来的类型, 比如在runtime-core.d.ts
中在
macros.d.ts
中The text was updated successfully, but these errors were encountered: