Miguel Frias
Miguel Frias

Reputation: 2710

Typescript import module error

Im kinda new working with typescript i haven this small test file im using to practice, and still dont get what is wrong here.

app.ts

import * as $ from 'jquery';
import { ShareModule } from './modules/share.module';

export class AppModule {
  constructor(public share: ShareModule) { }

  public getphotos(): void {
    this.share.logPhotos();
  }

}

const app = new AppModule();

share.module.ts

import * as $ from 'jquery';

export class ShareModule {
  public photos: any = [
    { name: 'string' },
    { name: 'string' },
    { name: 'string' },
    { name: 'string' },
    { name: 'string' },
    { name: 'string' }
  ];
  constructor() {
  }

  public logPhotos(): void {
    this.photos.forEach((photo) => {
      console.log(photo);
    });
  }
}

someone to help to understand why is wrong and where is error on the code, just to make a little bit more clear i have the error the const app = new Appmodule is expecting 1 argument and get 0.

Upvotes: 0

Views: 68

Answers (2)

Akash
Akash

Reputation: 4553

Constructor of AppModule requires a parameter. So a param has to be passes while using new AppModule(). Constructor param can be made optional by

constructor(public share ?: ShareModule) { }

Upvotes: 1

MjZac
MjZac

Reputation: 3526

The constructor is constructor(public share: ShareModule) { }. It is expecting an argument of type ShareModule. But you are not passing any.

Upvotes: 1

Related Questions