Skip to content

addEntity should return the type of the added entity #497

@aiwilliams

Description

@aiwilliams

In some integrations there is a type representing the entities created by the integration. Consider the following code:

function createGroupEntity(group: BitbucketGroup): BitbucketGroupEntity {
  return createIntegrationEntity({
    entityData: {
      source: group,
      assign: {
        displayName: group.name,
      },
    },
  }) as BitbucketGroupEntity;
}

export function createWorkspaceHasGroupRelationship(
  workspace: BitbucketWorkspaceEntity,
  group: BitbucketGroupEntity,
): BitbucketWorkspaceGroupRelationship {
  return {
    _key: `${workspace._key}|has|${group._key}`,
    _class: 'HAS',
    _type: BITBUCKET_WORKSPACE_GROUP_RELATIONSHIP_TYPE,
    _fromEntityKey: workspace._key,
    _toEntityKey: group._key,
    displayName: 'HAS',
  };
}

const workspaceEntity = ....;
const groupEntity = await jobState.addEntity(createGroupEntity(group)); // groupEntity is type Entity
createWorkspaceHasGroupRelationship(workspaceEntity, groupEntity); // < -- compilation problem

addEntity should return the type of the argument so that groupEntity: BitbucketGroupEntity.

Related to #270

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions