镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Determine if a method is deprecated in code #22524

Description

@dougwilson

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

  1. added
    questionIssues asking questions about Node.js.
    deprecationsIssues and PRs related to deprecations.
    on Aug 25, 2018
  2. mscdex commented on Aug 25, 2018

    @mscdex
    Contributor

    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:

    var getter = Object.getOwnPropertyDescriptor(obj, 'property').get;
    if (getter && getter.name === 'deprecated')
      // ...

    Having a core API for determining all of this might be a good idea though.

  3. cjihrig commented on Aug 25, 2018

    @cjihrig
    Contributor

    Seems like another potential use case for #22302 (cc: @MylesBorins)

  4. dougwilson commented on Aug 26, 2018

    @dougwilson
    MemberAuthor

    Ah, thanks @mscdex! I will work on a PR to add that to the util.deprecate docs 👍

  5. devsnek commented on Aug 26, 2018

    @devsnek
    Member

    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.

  6. dougwilson commented on Aug 26, 2018

    @dougwilson
    MemberAuthor

    I retract my offer to do this change. I'm going to stay away from Node.js core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    deprecationsIssues and PRs related to deprecations.questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions