Can't access property of interface to reference type in another interface
donaldpipowitch opened this issue · 3 comments
donaldpipowitch commented
TypeScript Version: 1.8.0 (Playground) / 2.1.0-dev
Code
interface Foo {
bar: string;
}
interface Box<T> {
container: T;
}
interface FooWithBoxedProps {
bar: Box<Foo.bar>;
}Expected behavior:
Behave exactly like this:
interface Foo {
bar: string;
}
interface Box<T> {
container: T;
}
interface FooWithBoxedProps {
bar: Box<string>;
}Actual behavior:
Cannot find namespace 'Foo'.
OlegDokuka commented
It is unreachable because Foo is not a name space, and variable bar is a part of instance of type Foo. In typescripts philosophy interface is virtual construction and you cant deal with it in any form except extending and inheritance (in other words it is compiler feature).
So, you cant deal with Foo as with namespace.
Also, you can try something like above to solve your problem
interface Foo {
bar: string;
}
namespace Foo {
export type bar= string;
}
interface Box<T> {
container: T;
}
interface FooWithBoxedProps {
bar: Box<Foo.bar>;
}donaldpipowitch commented
Which is closed in favor of #6606. I'll post my use case there. Thanks so far.