How to use the reference of a file of a barrel in the same folder with Typescript

2

I'm having trouble making reference to files that are in the same folder when working with a file of type barrel in my project is in Angular (version: ^ 4.0.0). My problem is this, look at the structure of files and directories below:

|-app
   |-index.ts
   |-app.module.ts
   |-app.routes.ts
   |-app.component.ts 
   |-foo
      |-index.ts
      |-foo.module.ts
      |-foo.routes.ts
      |-foo.component.ts

The two files of type index, contains a simple structure of "barrel" files, as shown here:

app / index.ts

export * from './app.module';
export * from './app.routes';
export * from './app.component';

app / foo / index.ts

export * from './foo.module';
export * from './foo.routes';
export * from './foo.component';

My problem is, when I'm in any file inside the app directory, I can call a barrel reference from foo, like this:

app.module.ts

import { FooRoutes, FooComponent } from './foo' // -> vai reconhecer o barrel
...

But if I inside the app/foo directory try to search for an existing file in its own barrel of error, it says that the element could not be found (returns undefined ). Serial something like:

foo.module.ts

import { FooComponent } from '../foo' // -> não acha
import { FooComponent } from '..' // -> não acha
import { FooComponent } from 'foo' // -> não acha
//wtf???
...

Can anyone help me solve this problem?

    
asked by anonymous 03.07.2017 / 16:54

1 answer

0

The solution was the way I was declaring the import because I should use the same logic for browsing between folders where . represents that I am fetching something in the same directory and .. in the previous directory. It would look like this:

import { FooComponent } from '.'; // funciona
import { FooComponent } from './index'; // também funciona
    
06.09.2018 / 16:01