是否可以以这样的方式键入字符串数组,使得该数组只能是给定对象中的有效属性路径?类型定义应该适用于所有深度嵌套的对象。
例子:
const object1 = {
someProperty: true
};
const object2 = {
nestedObject: object1,
anotherProperty: 2
};
type PropertyPath<Type extends object> = [keyof Type, ...Array<string>]; // <-- this needs to be improved
// ----------------------------------------------------------------
let propertyPath1: PropertyPath<typeof object1>;
propertyPath1 = ["someProperty"]; // works
propertyPath1 = ["doesntExist"]; // should not work
let propertyPath2: PropertyPath<typeof object2>;
propertyPath2 = ["nestedObject", "someProperty"]; // works
propertyPath2 = ["nestedObject", "doesntExist"]; // should not work
propertyPath2 = ["doesntExist"]; // should not work
Run Code Online (Sandbox Code Playgroud)
根据Vue.js的文档,它正在使用引擎盖下的VDOM来呈现UI.根据我的理解,VDOM主要是为了避免"跟踪依赖"而发明的.使用VDOM,可以在不知道确切更改的情况下协调应用程序的更大部分.因此,可以使用普通对象和数组来描述视图,只需要通知框架有关更改(如setState在React中).然后,比较两个VDOM树,并将最小的所需更改集应用于真实DOM.
另一方面,Vue.js使用跟踪的依赖关系.它确切地知道发生了什么变化,因此可以使用DOM绑定.此外,由于大多数Vue.js用户已经在使用模板语言,因此VDOM提供的更大灵活性并没有真正受益.那么为什么Evan决定使用VDOM?
frontend ×1
javascript ×1
jsonpointer ×1
recursion ×1
reflection ×1
rendering ×1
types ×1
typescript ×1
vue.js ×1