Skip to content

Typing - accessing children of a Sequence element #213

@paperflo

Description

@paperflo

Hi @b4rtaz,

I have a use case that's quite similar to the triggers example. As in that example, the first step in the root sequence is the launch pad. I am restricting it further such that only one trigger can be added, which functionally works well. To make the typing work I'm currently using a type assertion, because the sequence property isn't defined on the elements of Sequence.

const configuration: DesignerConfiguration = {
  placeholder: {
    canShow(
      sequence: Sequence,
      _index: number,
      _draggingStepComponentType: string,
      draggingStepType: string,
      definition: Definition
    ) {
      const launchPad = definition.sequence[0] as SequentialStep // here

      const isTriggerStep = draggingStepType === 'trigger'
      const isLaunchPadSequence = sequence === launchPad.sequence // to make this access possible
      const triggerExists = launchPad.sequence.length > 0 // and this one

      return (
        (isTriggerStep && isLaunchPadSequence && !triggerExists) ||
        (!isTriggerStep && !isLaunchPadSequence)
      )
    },
  },

  ...otherConfig,
}

Is there a way to make the typing work without the type assertion, something I've missed maybe?

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