Skip to content

pointer-support-cap.ts fails type-check unless the consumer enables noUncheckedIndexedAccess #617

Description

@Vasily-Zh

Summary

packages/editor/src/components/tools/shared/pointer-support-cap.ts only
type-checks when the consuming project enables noUncheckedIndexedAccess.

const belongsToActiveLevel = (nodeId: AnyNodeId) => {
  let current = nodes[nodeId]          // inferred as AnyNode (no `| undefined`)
  const visited = new Set<AnyNodeId>()
  while (current && !visited.has(current.id)) {
    if (current.id === levelId) return true
    visited.add(current.id)
    current = current.parentId ? nodes[current.parentId as AnyNodeId] : undefined
    //                                                                 ^^^^^^^^^
  }
  return false
}

With noUncheckedIndexedAccess: true (which the project itself uses) the
initializer is AnyNode | undefined and the assignment is fine. With the flag
off — a common, perfectly valid strict setup — the variable is inferred as
AnyNode and assigning undefined fails:

node_modules/@pascal-app/editor/src/components/tools/shared/pointer-support-cap.ts(166,9):
error TS2322: Type '... | undefined' is not assignable to type '...'.

The package ships TypeScript sources, so consumers type-check them. Turning on
noUncheckedIndexedAccess project-wide just to build a dependency isn't a fair
ask — it's a rule about all of the consumer's own code.

Suggested fix

Annotate the variable explicitly, which is correct under both settings:

let current: AnyNode | undefined = nodes[nodeId]

(AnyNode is already exported from @pascal-app/core.)

Version

@pascal-app/editor@1.0.0-beta.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions