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

Fix deprecation: Use symbol method for custom inspection #393

Merged
merged 3 commits into from
Jun 12, 2018
Merged

Fix deprecation: Use symbol method for custom inspection #393

merged 3 commits into from
Jun 12, 2018

Conversation

eritbh
Copy link
Contributor

@eritbh eritbh commented May 31, 2018

Setting inspect() on objects in order to modify the behavior of util.insect(obj) is deprecated and prints a warning as of Node 10. The alternative, [util.inspect.custom](), has been available since node 6.

Deprecation ref: nodejs/node#15549

This outdates the typescript defs - I don't know how to document symbol methods so I didn't touch them. If anyone else can, let me know and I'll update this PR.

@eritbh eritbh changed the title Fix deprecation: Use symbol method for custom inspecttion Fix deprecation: Use symbol method for custom inspection May 31, 2018
@Brayzure
Copy link
Contributor

I think this should be bundled in with node 6 changes, whenever we get to them. Additionally, we should probably grant users the same courtesy that node has, and deprecate this before removing it entirely.

@eritbh
Copy link
Contributor Author

eritbh commented Jun 1, 2018

What other Node 6 changes are there? Not familiar with that.

I guess that's a fair point, but I dunno if there's any case where it matters - does anyone use #inspect outside the util.inspect use?

If it does matter, that can be resolved by setting the two properties to the same value to silence the deprecation warning (the symbol version takes precedence): Base.prototype.inspect = Base.prototype[util.inspect.custom] would be backwards-compatible and not emit the warning on 10.x.

@abalabahaha
Copy link
Owner

Agree with Brayzure, no sense breaking Node 4 compatibility for this single change. Probably would be nicer to do it the other way around - set prototype[util.inspect.custom] to prototype.inspect if the symbol exists.

@abalabahaha abalabahaha merged commit 7aae930 into abalabahaha:dev Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants