Skip to content

NodeTypeUtil.isTypeOf is incorrectly typed #181

Description

@kling90

Noticed that the type definitions for NodeTypeUtil.isTypeOf expects the string arguments for types to be spread, but it actually expects an array of strings.

The type definition expect the following:

const TYPES = [
  NodeTypeUtil.PAGE_TYPE,
  NodeTypeUtil.COLLABORATION_GROUP_PAGE_TYPE,
  NodeTypeUtil.COLLABORATION_GROUP_TYPE,
  NodeTypeUtil.STRUCTURE_PAGE_TYPE,
];

function isValidType(node: Node) {
  return NodeTypeUtil.isTypeOf(node, ...TYPES);
}

But then you get a runtime error:

Can't find method com.sun.proxy.$Proxy175.isTypeOf(senselogic.sitevision.content.jcr.node.NodeImpl,string,string,string,string). (<sitevision>#338)

The following works, but reports a TypeScript error.

const TYPES = [
  NodeTypeUtil.PAGE_TYPE,
  NodeTypeUtil.COLLABORATION_GROUP_PAGE_TYPE,
  NodeTypeUtil.COLLABORATION_GROUP_TYPE,
  NodeTypeUtil.STRUCTURE_PAGE_TYPE,
];

function isValidType(node: Node) {
  return NodeTypeUtil.isTypeOf(node, TYPES);
}
Argument of type '[("sv:page" | "sv:collaborationGroupPage" | "sv:collaborationGroup" | "sv:structurePage")[]]' is not assignable to parameter of type 'String[] | string[]'.
  Type '[("sv:page" | "sv:collaborationGroupPage" | "sv:collaborationGroup" | "sv:structurePage")[]]' is not assignable to type 'string[]'.
    Type '("sv:page" | "sv:collaborationGroupPage" | "sv:collaborationGroup" | "sv:structurePage")[]' is not assignable to type 'string'.

The type definition for isTypeOf should propably be updated to:

/**
   * Checks a node against multiple node type names to see if any of them match.
   * @param aNode the node to be checked
   * @param aPrimaryNodeTypes the primary node type names <code>aNode</code> should be checked against
   * @return whether primary node type of <code>aNode</code> matches any of the types in <code>aPrimaryNodeTypes</code>
   */
- isTypeOf(aNode: Node, ...aPrimaryNodeTypes: String[] | string[]): boolean;
+ isTypeOf(aNode: Node, aPrimaryNodeTypes: String[] | string[]): boolean;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions