question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I use a constructor in a module?

See original GitHub issue

I need to do some initialization work whenever the module is constructed. But when I add the super(); call, it expects a module parameter. What should I pass in there?

@Module
export default class RealTime extends VuexModule {
    private playersOnline!: [];

    constructor() {
        super();
    }

    get getPlayersOnline() {
        return this.playersOnline;
    }
}; 

constructor VuexModule<ThisType<any>, any>(module: Module<ThisType<any>, any>): VuexModule<ThisType<any>, any> Expected 1 arguments, but got 0.ts(2554) vuexmodule.d.ts(16, 17): An argument for ‘module’ was not provided.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
championswimmercommented, Mar 18, 2019

Modules are not supposed to be constructed. Use getModule() to fetch a module object.

On Mon 18 Mar, 2019, 1:13 AM Magnus Johansson, notifications@github.com wrote:

I need to do some initialization work whenever the module is constructed. But when I add the super(); call, it expects a module parameter. What should I pass in there?

@Moduleexport default class RealTime extends VuexModule { private playersOnline!: [];

constructor() {
    super();
}

get getPlayersOnline() {
    return this.playersOnline;
}

};

constructor VuexModule<ThisType, any>(module: Module<ThisType, any>): VuexModule<ThisType, any> Expected 1 arguments, but got 0.ts(2554) vuexmodule.d.ts(16, 17): An argument for ‘module’ was not provided.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/championswimmer/vuex-module-decorators/issues/105, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQ_yiXDwsGJZAMc_22MJgfVjqcaGYGDks5vXpr3gaJpZM4b4mOf .

3reactions
Botvinkincommented, Jun 1, 2020

Modules are not supposed to be constructed. Use getModule() to fetch a module object.

This prevents me from using DI (inversify.js) with modules.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - use of module.exports as a constructor
CommonJS modules allow two ways to define exported properties. In either case you are returning an Object/Function.
Read more >
constructor - JavaScript - MDN Web Docs - Mozilla
The constructor method is a special method of a class for creating and initializing an object instance of that class.
Read more >
Javascript module pattern with constructor with arguments
The constructor is defined as it is usually done in Javascript. The module pattern has been used in the prototype implementation, where we...
Read more >
How to export default constructors ? - GeeksforGeeks
The export statement is used to bind one JavaScript module to others. In order to export the default constructor, we use an export...
Read more >
Classes and Modules | Advanced JavaScript
In this example, we created a subclass that extended our House class. The Mansion subclass has a defined constructor, so we must call...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found