socket-controllers icon indicating copy to clipboard operation
socket-controllers copied to clipboard

fix: if controllers array is empty or undefined i have error "Cannot read property 'filter' of undefined"

Open alexgev opened this issue 3 years ago • 2 comments

Description

When i use useSocketServer(io) without controllers array in options i have error "Cannot read property 'filter' of undefined" Minimal code-snippet showcasing the problem

useSocketServer(io);

In src/index.js:36

if (options && options.controllers && options.controllers.length)
    controllerClasses = (options.controllers as any[]).filter(controller => controller instanceof Function);
  const controllerDirs = (options.controllers as any[]).filter(controller => typeof controller === 'string');
  controllerClasses.push(...importClassesFromDirectories(controllerDirs));

please, add scopes for if

Expected behavior

doesnt get error

Actual behavior

get error

alexgev avatar Mar 11 '21 14:03 alexgev

Care to open a PR?

NoNameProvided avatar Mar 23 '21 16:03 NoNameProvided

yes

alexgev avatar Mar 23 '21 16:03 alexgev

Should be fixed in the latest release.

attilaorosz avatar Jan 20 '23 19:01 attilaorosz

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Feb 20 '23 01:02 github-actions[bot]