Skip to content

"Wrong returns value" warning ignores subclasses (@class and @extends support) #31

Open
@cowwoc

Description

@cowwoc

Given:

        /**
         * Create a new precondition.
         *
         * @param {Object} parameter the parameter value
         * @param {String} name the parameter name
         * @return {ObjectPreconditions} the precondition
         */
        Preconditions.requireThat = function(parameter, name)
        {
            ObjectPreconditions.instanceOf(name, "name", String);
            if (Utilities.instanceOf(parameter, String))
                return new StringPreconditions(parameter, name);
            if (Array.isArray(parameter))
                return new ArrayPreconditions(parameter, name);
            return new ObjectPreconditions(parameter, name);
        };

where ArrayPreconditions and StringPreconditions both subclass ObjectPreconditions as follows:

        /**
         * @class ObjectPreconditions
         */
    function ObjectPreconditions(parameter, name)
    {
          ...
        }

        /**
         * @class StringPreconditions
         * @extends ObjectPreconditions
         */
    function StringPreconditions(parameter, name)
    {
      ...
    }
    StringPreconditions.prototype = Object.create(ObjectPreconditions.prototype);
    StringPreconditions.prototype.constructor = ObjectPreconditions;

I am expecting to be able to return ObjectPreconditions without having to specify every possible subclass. From the end-user's point of view, the subclasses are an implementation detail.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions