Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Angular 2 and Typescript - Importing multiple interfaces from a single file

I've tried searching high and low for an answer to this but hopefully someone will be able to answer this quickly.

I have a Angular 2 app and I'm using Typescript interfaces to help structure various bits of data. The issue is that I have one file with multiple interfaces and when I try to import that into a component, the first interface can be referenced without problems, but the second one causes an error.

For example ...

myapp.model.ts
  export interface IObjectA { id: number; name: string; }
  export interface IObjectB { id: number; related: IObjectA[]; }

myapp.component.ts
  import { IObjectB } from './myapp.model';

This results in the Angular CLI compiler to fail with the error ...

... myapp.model.ts is not a module ...

I can't seem to work out how to solve this one. I'm sure I'm missing something very obvious, but you know what they say about a second pair of eyes.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It seems this issue was caused by a problem with my angular cli compiler (the one that is started with NG SERVE). Once I stopped and restarted NG SERVE, the issue went away. I could have multiple interfaces in one file and successfully import them into my components.

For everyone's information, I'm running (ng -v) ...

  • Angular 4.0.1
  • @angular/cli 1.0.0
  • Node 7.5.0
  • Typescript 2.2.2

Hopefully that helps...

about 4 years ago · Santiago Trujillo Relatório

0

Make your interfaces in each separate file. I.e make objectA.ts and objectB.ts I think this is a bug in angular-cli. If you want to dig deeper take a look at this

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda