如何提取嵌套属性的类型?例如说我有这种类型:
type Example = {
nested: string, // how do I infer string here
other: string
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以从 Example.nested 中提取出“字符串”?
我有type myType = Pick<Example, "nested">并且提供了{ nested: string },但我想推断该对象上的属性“嵌套”(在本例中为字符串)的类型。
我正在尝试使用 Vue 和 TypeScript。我正在尝试在我的 tsconfig 中编译为 AMD。
Vue.js 自带的类型定义在 vue/types/index.d.ts 中说明
export default Vue;
Run Code Online (Sandbox Code Playgroud)
但是,这会导致打字稿编译:
import Vue as "vue";
export default Vue.extend({ ... });
Run Code Online (Sandbox Code Playgroud)
基本上,进入这个:
define(["vue"], function(vue) {
exports.default = vue.default.extend({ ... })
});
Run Code Online (Sandbox Code Playgroud)
请注意,它认为 vue 应该有一个属性 .default,而它没有。无论如何要编写一个类型定义来覆盖默认的 vue 类型定义,该类型定义如下:
export = Vue;
Run Code Online (Sandbox Code Playgroud)
或者 tsconfig 中的一些标志告诉打字稿不要将该 .default 属性添加到已编译的 AMD 模块中?