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

Having issue with class inheritance and circular references #443

Open
jacobbrown0192 opened this issue Aug 5, 2021 · 0 comments
Open

Having issue with class inheritance and circular references #443

jacobbrown0192 opened this issue Aug 5, 2021 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@jacobbrown0192
Copy link

Description

I am having an issue with class inheritance and I am not sure if it is a bug or something that I misunderstand.

The situation goes like so: I have a generic class called Base, This class is extended to create a notification class. I have another class used for event dispatching, which dispatches events to the notification class. The base class has an instance of the event dispatcher. Finally, I have another class the extends Base that will send events to the dispatcher called EventSend.

The problem is if all of these four classes are defined in separate files I get a type error
TypeError: Class extends value undefined is not a constructor or null

However, If I bring the notification class into the base class file it compiles and works fine.

//test file
import 'reflect-metadata';
import { Container } from '../../../src/index';
import { EventSend } from './eventsend';

describe('Github Issue', function () {
  it('My Issue', () => {
    const eventSend = Container.get(EventSend);
  });
});
// dispatcher.ts
import { Inject, Service } from '../../../src';
import { Notifications } from './notifications';

@Service()
export class Dispatcher {
  @Inject(() => Notifications)
  notifications: Notifications
}
// notifications.ts
import { Service } from '../../../src';
import { Base } from './base';

@Service()
export class Notifications extends Base {}
// event-send.ts
import { Service } from '../../../src';
import { Base } from './base';

@Service()
export class EventSend extends Base {}
// base.ts
import { Inject, Service } from '../../../src';
import { Dispatcher } from './dispatcher';

@Service()
export class Base {
  @Inject(() => Dispatcher)
  public dispatcher: Dispatcher
}

Expected behavior

I would hope this can work with not having my subclass defined in the same file

Actual behavior

Throws error TypeError: Class extends value undefined is not a constructor or null

@jacobbrown0192 jacobbrown0192 added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant