1
我如何引用typecript定义的嵌套属性的类型?这是我的尝试:Typescript:如何引用接口上的嵌套类型?
// def.d.ts
declare module Def {
type TFoo = {
bar: (...args) => void;
}
}
// script.ts
const bar: Def.TFoo.bar = function() {}; // Error TS2694: Namespace 'Def' has no exported member 'TFoo'
我知道我可以单独定义并引用它:
// def.d.ts
declare module Def {
type TFooBar = (...args) => void;
type TFoo = {
bar: TFooBar;
}
}
// script.ts
const bar: Def.TFooBar = function (...args) {};
但我想用的定义更命名空间的方式,就像上面的例子。我如何实现这一目标?