Issue: dock-layout Library TypeScript Build Errors

Pre-existing strict null check errors prevent gograb-dev from building for production

Issue: dock-layout Library TypeScript Build Errors

Summary

The libs/libs-ui/dock-layout library has 30+ TypeScript strict null check errors that prevent the unified-builder library (and transitively, gograb-dev) from building in production mode. This blocks Cloudflare Pages deployment of the gograb-dev app.

Build Failure Chain

gograb-dev:build:production
  └── unified-builder:build:production  ← FAILS HERE
        └── dock-layout (TypeScript compilation errors)

Error Categories

1. Object Possibly Undefined (TS2532 / TS18048) -- ~25 errors

Variables that could be undefined are used without null checks.

Affected files:

Example:

// TS18048: 'parent' is possibly 'undefined'
parent.children  // needs: parent?.children or parent!.children

2. Property Does Not Exist on Type (TS2339) -- ~8 errors

Accessing properties on discriminated union types without narrowing.

Affected files:

Example:

// TS2339: Property 'children' does not exist on type 'LayoutNode'
// Property 'children' does not exist on type 'TabsLayoutNode'
parent.children  // needs type narrowing: if ('children' in parent)

3. Type Assignability (TS2322 / TS2345 / TS2538) -- ~10 errors

Return types or argument types don't match expected types.

Affected files:

Recommended Fix Strategy

Option A: Targeted Null Checks (Recommended)

Add proper null guards and type narrowing where needed. This is the safest approach.

// Before
const idx = parent.children.indexOf(nodeId);

// After
if (!parent || !('children' in parent)) return;
const idx = parent.children.indexOf(nodeId);

Option B: Non-null Assertions (Quick Fix)

Use ! operator where the value is guaranteed by runtime logic but TypeScript can't infer it.

// Before
parent.children  // TS error

// After
parent!.children  // suppresses error

Option C: Disable Strict Null Checks for Library (Not Recommended)

Could add "strictNullChecks": false to the library's tsconfig, but this hides real bugs.

File Inventory

File Errors Primary Issue
layout-tree.utils.ts 30+ Undefined parents, union type narrowing
dock-state.service.ts 7 Type never access, undefined params
dock-drag.service.ts 5 Undefined tab references
dock-split.component.ts 3 Undefined object access
dock-layout.service.ts 3 Undefined + type assignability
dock-keyboard.service.ts 1 undefined vs null mismatch
hit-testing.utils.ts 1 Undefined access
layout-builder.utils.ts 1 Undefined as index

Resolution (Session 103)

All 30+ TypeScript strict null check errors were fixed across 8 files. The errors surfaced during production builds because the custom Angular library builder compiles with stricter settings than the default tsconfig.base.json.

Fix Strategy

The fixes applied targeted null safety without changing runtime behavior:

  1. Non-null assertions (!) — where array access is guaranteed by loop bounds or prior length checks (e.g., registeredTabs[0]!, stack[stack.length - 1]! after if (stack.length === 0) return)
  2. Nullish coalescing (??) — for safe fallback values (e.g., resizeStartSizes[index] ?? 0)
  3. Optional chaining (?.) — for map lookups that may return undefined (e.g., state.nodes[id]?.type)
  4. Type guard filters — replacing .filter(Boolean) with .filter((n): n is LayoutNode => !!n) for proper type narrowing
  5. Null checks on parent lookups — adding if (parent && parent.type === 'split') instead of just if (parent.type === 'split') throughout layout-tree.utils.ts
  6. Type assertions (as LayoutNode) — for spread operations that lose discriminated union type info

Files Fixed (8 total)

File Errors Fixed Fix Type
dock-split.component.ts 3 ?? fallback, ! assertion
dock-drag.service.ts 5 ! on loop-bounded array access
dock-keyboard.service.ts 1 ?? '' fallback
dock-layout.service.ts 3 ?. optional chaining, ! assertion
dock-state.service.ts 2 ! after length guard
hit-testing.utils.ts 1 ! on guaranteed array element
layout-builder.utils.ts 1 Conditional index access
layout-tree.utils.ts ~20 Null checks, type guards, as casts

Build Verification

Impact

Related