Search code examples
javascriptsymfonyecmascript-6phpstormstimulusjs

Error: Void function return value is used


I use Stimulus in Symfony 5 and when I use this code in my Stimulus controller, PhpStorm shows an error.

How can I fix this?

import {Controller} from 'stimulus';
import {index} from "../js/index";
export default class extends Controller{
    connect(){
        const index1 = index();
    }
}

Error: Void function return value is used

My index() function is:

export function index(){
...
}

Solution

  • Use this code:

    import {Controller} from 'stimulus';
    import Index from "../js/index";
    export default class extends Controller{
        connect(){
            const index1 = new Index;
            index1.index();
        }
    }
    

    And use this for your index class:

    export default class Index {
        index(){
            ...
        }
    }