---
name: Missing Type Definitions & Code Fixes
status: closed
created: 2025-10-13T11:02:21Z
updated: 2025-10-14T07:39:16Z
completed: 2025-10-13T17:15:00Z
github: https://github.com/BuzzTrail/video-extension/issues/131
depends_on: [002, 003]
parallel: false
conflicts_with: []
---
When changing versions or addding or subtracking packages always use pnpm commands.  Don't just edit the package.json directly.

# Task: Missing Type Definitions & Code Fixes

## Description

Add missing `@types/*` packages for third-party dependencies, create custom type definition files for untyped libraries, fix incorrect type annotations in source code, and remove unnecessary `any` types throughout the codebase.

## Acceptance Criteria

- [ ] All missing `@types/*` packages identified and installed
- [ ] Custom `.d.ts` files created for untyped dependencies
- [ ] All incorrect type annotations fixed
- [ ] `any` types replaced with proper types or `unknown`
- [ ] Generic types added where needed for reusability
- [ ] TypeScript compilation succeeds with 0 errors
- [ ] No type safety regressions introduced

## Technical Details

**Phase 1: Install Missing @types Packages**

Common packages that may need types:
```bash
pnpm add -D @types/node
pnpm add -D @types/express
pnpm add -D @types/ws
pnpm add -D @types/uuid
# Add others as discovered in Task 001
```

**Phase 2: Create Custom Type Definitions**

For untyped packages, create `.d.ts` files in appropriate locations:
```typescript
// libs/shared/types/src/lib/custom.d.ts
declare module 'untyped-package' {
  export function doSomething(param: string): void;
  export interface SomeType {
    id: string;
    name: string;
  }
}
```

**Phase 3: Fix Incorrect Type Annotations**

Common patterns to fix:
```typescript
// ❌ Before
const data: any = await fetchData();
function processData(input: any) { ... }

// ✅ After
const data: UserData = await fetchData();
function processData(input: unknown) {
  if (!isUserData(input)) {
    throw new Error('Invalid input');
  }
  // Now TypeScript knows input is UserData
}
```

**Phase 4: Add Generics Where Needed**

```typescript
// ❌ Before
function getData() {
  return api.fetch('/data');
}

// ✅ After
function getData<T>(): Promise<T> {
  return api.fetch<T>('/data');
}
```

**Files Likely to Need Updates**:
- `libs/shared/utils/src/lib/api-clients/*.ts`
- `apps/slide-system/src/lib/*.ts`
- `libs/tavus/src/lib/*.ts`
- Any file with `any` type annotations

**Testing**:
```bash
# Verify type safety
pnpm nx run-many -t typecheck --all

# Run tests to ensure no runtime regressions
pnpm nx affected:test
```

## Dependencies

- [ ] Task 002 completed (OpenTelemetry conflicts resolved)
- [ ] Task 003 completed (config fixes applied)
- [ ] Error inventory from Task 001

## Effort Estimate

- **Size**: M
- **Hours**: 3 hours
- **Parallel**: false (depends on config and dependency fixes)

## Definition of Done

- [ ] All missing type packages installed
- [ ] Custom type definitions created for untyped libraries
- [ ] All incorrect type annotations fixed
- [ ] `any` types eliminated or justified with comments
- [ ] TypeScript compilation succeeds with 0 errors
- [ ] All tests pass
- [ ] Code review completed
- [ ] Type safety improvements documented
