Skip to content

Conversation

@nperez0111
Copy link

Idea is that instead of having a whole RecursiveDelta type, add a type arg to a Delta (Recursive=boolean) which can be used to check whether a delta is recursive or not, and then typecheck based on that flag instead of having to construct the whole type. TS doesn't do well with recursive types, since technically this is infinite. It's better to have it check constraints rather than have to build out whole type trees

This code was failing to type-check before:

const $prosemirrorDelta = $delta({ name: s.$string, attrs: s.$record(s.$string, s.$any), text: true, recursive: true })

/**
 * @typedef {s.Unwrap<typeof $prosemirrorDelta>} ProsemirrorDelta
 */

/**
 *
 * @param {ProsemirrorDelta} delta
 */
function prosemirrorDelta (delta) {
  const { children } = delta
  for (const child of children) {
    console.log(child)
  }
}

And, now it can, since we don't use the RecursiveDelta anymore

@nperez0111 nperez0111 changed the title fix: add a Recursive type argument, to avoid excessive instantiation fix(delta): add a Recursive type argument, to avoid excessive instantiation Dec 15, 2025
@nperez0111 nperez0111 changed the title fix(delta): add a Recursive type argument, to avoid excessive instantiation [delta] add a Recursive type arg, avoiding excessive instantiation Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant