You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Determine if a method is deprecated in code #22524
I'm looking for a method in which use-land Node.js code can determine if a method in Node.js has been marked deprecated or not prior to calling it. It looks like this is typically done with util.deprecate. It seems like from an issue discussion the method to do this is to use .propertyIsEnumerable. Is this the correct way to go about this type of detection?
If this is the agreeable way to detect the deprecated things in Node.js, I can volunteer to make a pull request to update the util.deprecate documentation and add a test to the test suite to validate things from util.deprecate work this way. I just wanted to make sure I'm understanding correctly and this is the right path for user-land detection prior to opening a PR 👍
Edit: I opened this as it's own issue so conversation wouldn't get lost in an unrelated PR.
Activity
mscdex commentedon Aug 25, 2018
Currently, for functions you could just check
fn.name === 'deprecated'or something similar since deprecated methods are wrapped.Similarly for non-function properties you could do something like:
Having a core API for determining all of this might be a good idea though.
cjihrig commentedon Aug 25, 2018
Seems like another potential use case for #22302 (cc: @MylesBorins)
dougwilson commentedon Aug 26, 2018
Ah, thanks @mscdex! I will work on a PR to add that to the util.deprecate docs 👍
devsnek commentedon Aug 26, 2018
in some carnation of adding esm to the builtin modules I had a WeakSet of all the deprecated functions (incl. getters) which worked fairly well.
dougwilson commentedon Aug 26, 2018
I retract my offer to do this change. I'm going to stay away from Node.js core.