Node: events: type of eventName allowed besides string/symbol

Created on 12 Jan 2020  路  5Comments  路  Source: nodejs/node

  • Version: 13.6.0
  • Platform: all
  • Subsystem: events

Docs tell that eventName should be of type string or symbol. But actually there is no type check and it works to use e.g. number, function or null - they just get coerced to a string (which is quite nice for functions).

There are also two tests which use non string/symbol: e.g. test-event-emitter-max-listeners-warning-for-null.js and test-event-emitter-subclass.js.

Are the docs wrong or the implementation? Or is this just some relict which can't be changed but should be hidden in docs as there were already type checks implemented (see https://github.com/nodejs/node/commit/04688614f70470dba1f7512844fd2c4008d9d8bd).

Edit:
Maybe some more background on this: I worked on adding typechecks for types and at that time I discovered a few failing tests and as followup the commit linked above.

Most helpful comment

FWIW, I tried to add type validation in https://github.com/nodejs/node/pull/21007. I can revisit that if we actually want that validation.

All 5 comments

I think we shouldn鈥檛 tell people they could do that, even we support. And that commit just for backwards compatibility for other libraries.

FWIW, I tried to add type validation in https://github.com/nodejs/node/pull/21007. I can revisit that if we actually want that validation.

Seems like this is an area which should not be touched. There were already type checks which got removed and a later try to add them was given up.

I'd +1 some better type checking here.

Perf impact of type checks seems to be too high, see #31428

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielstaleiny picture danielstaleiny  路  3Comments

Brekmister picture Brekmister  路  3Comments

Icemic picture Icemic  路  3Comments

cong88 picture cong88  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments