Skip to content
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

Can't access property of interface to reference type in another interface #10588

Closed
donaldpipowitch opened this issue Aug 29, 2016 · 3 comments
Closed

Comments

@donaldpipowitch
Copy link
Contributor

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
Copy link

OlegDokuka commented Aug 29, 2016

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>;
}

@mhegazy
Copy link
Contributor

mhegazy commented Aug 29, 2016

duplicate of #4640

@donaldpipowitch
Copy link
Contributor Author

donaldpipowitch commented Aug 29, 2016

Which is closed in favor of #6606. I'll post my use case there. Thanks so far.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants