Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .cursor/rules/strict-broker-protection-actions.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
description: "Subagent task: Fix strict TypeScript errors in broker-protection action files and add to CORE_FILES"
globs:
- "scripts/check-strict-core.js"
- "injected/src/features/broker-protection/actions/build-url.js"
- "injected/src/features/broker-protection/actions/build-url-transforms.js"
- "injected/src/features/broker-protection/actions/captcha-callback.js"
- "injected/src/features/broker-protection/actions/captcha-deprecated.js"
- "injected/src/features/broker-protection/actions/click.js"
- "injected/src/features/broker-protection/actions/extract.js"
- "injected/src/features/broker-protection/actions/fill-form.js"
---

# Strict TypeScript: Broker Protection Actions

## Task

Fix all strict-mode TypeScript errors in 7 broker-protection action files and add them to `CORE_FILES`.

## Branch

```
git checkout main && git pull origin main && git checkout -b cursor/strict/broker-protection-actions
```

## Files (39 errors total)

### `injected/src/features/broker-protection/actions/build-url.js` (3 errors)
```
(11,26): error TS7006: Parameter 'action' implicitly has an 'any' type.
(27,37): error TS7006: Parameter 'action' implicitly has an 'any' type.
(27,45): error TS7006: Parameter 'userData' implicitly has an 'any' type.
```

### `injected/src/features/broker-protection/actions/build-url-transforms.js` (5 errors)
```
(68,52): error TS7006: Parameter 'range' implicitly has an 'any' type.
(149,41): error TS2345: Argument of type 'string | number | undefined' is not assignable to parameter of type 'string | number'.
(168,50): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
(177,21): error TS7006: Parameter 's' implicitly has an 'any' type.
(179,41): error TS7006: Parameter 'word' implicitly has an 'any' type.
```

### `injected/src/features/broker-protection/actions/captcha-callback.js` (12 errors)
```
(13,16): error TS2532: Object is possibly 'undefined'.
(13,27): error TS2339: Property 'function' does not exist on type '{ id: string; version: string; }'.
(15,13): error TS2532: Object is possibly 'undefined'.
(15,24): error TS2339: Property 'function' does not exist on type '{ id: string; version: string; }'.
(16,54): error TS2532: Object is possibly 'undefined'.
(16,65): error TS2339: Property 'callback' does not exist on type '{ id: string; version: string; }'.
(50,26): error TS2339: Property 'pageurl' does not exist on type '{ id: string; version: string; }'.
(56,26): error TS2339: Property 'sitekey' does not exist on type '{ id: string; version: string; }'.
(60,30): error TS2339: Property 'callback' does not exist on type '{ id: string; version: string; }'.
(61,30): error TS2339: Property 'function' does not exist on type '{ id: string; version: string; }'.
(63,30): error TS2339: Property 'function' does not exist on type '{ id: string; version: string; }'.
(64,30): error TS2339: Property 'callback' does not exist on type '{ id: string; version: string; }'.
```

### `injected/src/features/broker-protection/actions/captcha-deprecated.js` (1 error)
```
(95,30): error TS7006: Parameter 'action' implicitly has an 'any' type.
```

### `injected/src/features/broker-protection/actions/click.js` (6 errors)
```
(48,102): error TS18046: 'error' is of type 'unknown'.
(69,31): error TS18048: 'elem' is possibly 'undefined'.
(74,28): error TS18048: 'elem' is possibly 'undefined'.
(196,63): error TS18046: 'error' is of type 'unknown'.
(203,79): error TS18046: 'error' is of type 'unknown'.
(211,72): error TS18046: 'error' is of type 'unknown'.
```

### `injected/src/features/broker-protection/actions/extract.js` (9 errors)
```
(94,37): error TS7006: Parameter '_' implicitly has an 'any' type.
(94,40): error TS7006: Parameter 'value' implicitly has an 'any' type.
(141,13): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
(156,13): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
(173,28): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ profileUrl: ... }'.
(177,28): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ profileUrl: ... }'.
(205,11): error TS7034: Variable 'matchedFields' implicitly has type 'any[]'.
(211,18): error TS7005: Variable 'matchedFields' implicitly has an 'any[]' type.
(376,27): error TS7006: Parameter 'link' implicitly has an 'any' type.
```

### `injected/src/features/broker-protection/actions/fill-form.js` (3 errors)
```
(111,31): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type (US state map).
(232,25): error TS7006: Parameter 'element' implicitly has an 'any' type.
(258,40): error TS18046: 'e' is of type 'unknown'.
```

## Fix Patterns

- **TS7006** (Parameter implicitly any): Add `@param {Type}` JSDoc annotations. Look at how the param is used and what calling code passes.
- **TS2339** (Property doesn't exist): The type `{ id: string; version: string; }` in captcha-callback.js is too narrow — find the actual type definition or extend it with the missing properties via `@typedef`.
- **TS2532/TS18048** (Possibly undefined): Add null checks before accessing.
- **TS18046** ('error' is unknown): Cast or check `error instanceof Error` before accessing `.message`.
- **TS7053** (No index signature): Use `Record<string, X>` casts or narrow index types.
- **TS7034/TS7005** (Variable implicitly any): Add explicit type annotations at declaration.
- **TS2345** (Argument not assignable): Add null/undefined guards or narrow types.

## Workflow

1. `npm ci`
2. Add all 7 files to CORE_FILES in `scripts/check-strict-core.js`
3. Fix each file's errors using JSDoc type annotations
4. `npm run tsc-strict-core` — must pass
5. `npm run test-unit` — must pass
6. `npm run lint` — must pass (run `npm run lint-fix` first if needed)
7. Commit: `fix(types): add strict checking for broker-protection action files`
8. `git push -u origin cursor/strict/broker-protection-actions`

## Constraints

- Do NOT use `any` — use `unknown`, specific types, or proper interfaces
- Do NOT use `@ts-ignore` or `@ts-expect-error`
- Do NOT modify files outside the assigned list (except `scripts/check-strict-core.js`)
- Do NOT remove existing CORE_FILES entries
- Preserve existing behavior — type fixes only, no logic changes
109 changes: 109 additions & 0 deletions .cursor/rules/strict-broker-protection-rest.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
description: "Subagent task: Fix strict TypeScript errors in remaining broker-protection files and add to CORE_FILES"
globs:
- "scripts/check-strict-core.js"
- "injected/src/features/broker-protection.js"
- "injected/src/features/broker-protection/captcha-services/captcha.service.js"
- "injected/src/features/broker-protection/captcha-services/providers/cloudflare-turnstile.js"
- "injected/src/features/broker-protection/comparisons/address.js"
- "injected/src/features/broker-protection/comparisons/is-same-age.js"
- "injected/src/features/broker-protection/execute.js"
- "injected/src/features/broker-protection/extractors/address.js"
- "injected/src/features/broker-protection/utils/utils.js"
---

# Strict TypeScript: Broker Protection (Rest)

## Task

Fix all strict-mode TypeScript errors in 8 remaining broker-protection files and add them to `CORE_FILES`.

## Branch

```
git checkout main && git pull origin main && git checkout -b cursor/strict/broker-protection-rest
```

## Files (22 errors total)

### `injected/src/features/broker-protection.js` (3 errors)
```
(44,66): error TS18046: 'e' is of type 'unknown'.
(80,20): error TS7006: Parameter 'action' implicitly has an 'any' type.
(121,43): error TS7006: Parameter 'x' implicitly has an 'any' type.
```

### `injected/src/features/broker-protection/captcha-services/captcha.service.js` (1 error)
```
(80,26): error TS2345: Argument of type 'string | PirError' is not assignable to parameter of type 'object'.
```

### `injected/src/features/broker-protection/captcha-services/providers/cloudflare-turnstile.js` (4 errors)
```
(74,30): error TS2345: Argument of type 'string | PirError' is not assignable to parameter of type 'object'.
(82,30): error TS2345: Argument of type 'HTMLElement | PirError | null' is not assignable to parameter of type 'object'.
(111,30): error TS2345: Argument of type 'string | PirError' is not assignable to parameter of type 'object'.
(122,24): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
```

### `injected/src/features/broker-protection/comparisons/address.js` (2 errors)
```
(17,42): error TS7006: Parameter 'stateAbbreviation' implicitly has an 'any' type.
(24,12): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type (US state map).
```

### `injected/src/features/broker-protection/comparisons/is-same-age.js` (2 errors)
```
(6,27): error TS7006: Parameter 'userAge' implicitly has an 'any' type.
(6,36): error TS7006: Parameter 'ageFound' implicitly has an 'any' type.
```

### `injected/src/features/broker-protection/execute.js` (1 error)
```
(43,46): error TS18046: 'e' is of type 'unknown'.
```

### `injected/src/features/broker-protection/extractors/address.js` (1 error)
```
(4,26): error TS7016: Could not find a declaration file for module 'parse-address'.
```

### `injected/src/features/broker-protection/utils/utils.js` (8 errors)
```
(101,40): error TS7006: Parameter 'selector' implicitly has an 'any' type.
(116,37): error TS7006: Parameter 'selector' implicitly has an 'any' type.
(132,42): error TS7006: Parameter 'selector' implicitly has an 'any' type.
(151,45): error TS7006: Parameter 'selector' implicitly has an 'any' type.
(239,13): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
(242,28): error TS7006: Parameter 'a' implicitly has an 'any' type.
(242,31): error TS7006: Parameter 'b' implicitly has an 'any' type.
(256,34): error TS7006: Parameter 'profile' implicitly has an 'any' type.
```

## Fix Patterns

- **TS7006** (Parameter implicitly any): Add `@param {Type}` JSDoc.
- **TS18046** ('e' is unknown): Use `error instanceof Error ? error.message : String(error)` pattern.
- **TS2345** (Argument not assignable): Narrow types with guards or adjust the function signature upstream.
- **TS7016** (No declaration file for module): Add `// @ts-ignore` only as last resort, or create a minimal `.d.ts` declaration in the project. Better: use `/** @type {import('parse-address')} */` if types exist, or `/** @type {Record<string, Function>} */` for the default import.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d remove the @ts-ignore escape hatch here. A minimal local module declaration or typed adapter keeps strict checking useful without creating a pattern that can suppress security-relevant type contract issues in injected code.

- **TS2314** (Generic requires type args): Change `Array` → `Array<string>` or appropriate type.
- **TS7053/TS7015** (No index signature): Cast with `Record<string, X>` or narrow the index.

## Workflow

1. `npm ci`
2. Add all 8 files to CORE_FILES in `scripts/check-strict-core.js`
3. Fix each file's errors
4. `npm run tsc-strict-core` — must pass
5. `npm run test-unit` — must pass
6. `npm run lint` — must pass (run `npm run lint-fix` first if needed)
7. Commit: `fix(types): add strict checking for broker-protection files`
8. `git push -u origin cursor/strict/broker-protection-rest`

## Constraints

- Do NOT use `any` — use `unknown`, specific types, or proper interfaces
- Do NOT use `@ts-ignore` or `@ts-expect-error` (except for the `parse-address` module if no types exist)
- Do NOT modify files outside the assigned list (except `scripts/check-strict-core.js`)
- Do NOT remove existing CORE_FILES entries
- Preserve existing behavior — type fixes only, no logic changes
116 changes: 116 additions & 0 deletions .cursor/rules/strict-click-to-load.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
description: "Subagent task: Fix strict TypeScript errors in click-to-load files and add to CORE_FILES"
globs:
- "scripts/check-strict-core.js"
- "injected/src/features/click-to-load.js"
- "injected/src/features/click-to-load/components/ctl-login-button.js"
---

# Strict TypeScript: Click-to-Load

## Task

Fix all strict-mode TypeScript errors in 2 click-to-load files and add them to `CORE_FILES`. This is the largest single-file effort (169 errors in click-to-load.js).

## Branch

```
git checkout main && git pull origin main && git checkout -b cursor/strict/click-to-load
```

## Files (170 errors total)

### `injected/src/features/click-to-load.js` (169 errors)

**Key error categories:**

1. **Variables `styles`, `sharedStrings`, `config`, `appID`, `entities`, `readyToDisplayPlaceholdersResolver`, `afterPageLoadResolver` implicitly any (TS7034/TS7005)** — ~100 errors. These module-level variables are initialized as `undefined`/empty and assigned later. Add explicit `/** @type {X} */` at declaration.

2. **Property access on `Object` or `{}` typed params (TS2339/TS7053)** — ~30 errors. Config objects need proper typing. Define `@typedef` for the config shape, element data, etc.

3. **Parameter implicitly any (TS7006)** — ~5 errors. Add `@param` annotations.

4. **Type incompatibility (TS2322)** — `(originalElement: HTMLIFrameElement, ...)` vs `(originalElement: HTMLElement | HTMLIFrameElement, ...)`. Widen the parameter type.

5. **`this` implicitly any (TS2683)** — Arrow functions or explicit `@this` annotations.

6. **Cannot invoke possibly null (TS2721)** — Add null checks before invoking.

7. **No initializer (TS2564)** — `#messagingContext` property. Add `!` definite assignment assertion or initialize.

8. **displayMode index (TS7053)** — Cast the enum/string to the correct key type.

**Strategy for `styles` variable (~80 of the 169 errors):** The `styles` variable is used extensively. Find where it's assigned (likely from config) and type it with a comprehensive `@typedef` capturing all style properties used throughout the file. A single proper type annotation at the declaration eliminates ~80 errors.

**Strategy for `sharedStrings`:** Same approach — find the shape from config and type it.

### `injected/src/features/click-to-load/components/ctl-login-button.js` (1 error)
```
(23,5): error TS2564: Property '#element' has no initializer and is not definitely assigned in the constructor.
```

## Full Error List for click-to-load.js

```
(31,5): TS7034: Variable 'appID' implicitly has type 'any'
(37,5): TS7034: Variable 'config' implicitly has type 'any'
(38,5): TS7034: Variable 'sharedStrings' implicitly has type 'any'
(39,5): TS7034: Variable 'styles' implicitly has type 'any'
(60,7): TS7034: Variable 'entities' implicitly has type 'any[]'
(69,5): TS7034: Variable 'readyToDisplayPlaceholdersResolver' implicitly has type 'any'
(77,5): TS7034: Variable 'afterPageLoadResolver' implicitly has type 'any'
(119,44): TS2339: Property 'clickAction' does not exist on type 'Object'
(120,43): TS2339: Property 'replaceSettings' does not exist on type 'Object'
(122,9): TS7008: Member 'placeholderElement' implicitly has an 'any' type
(195,13): TS7053: Element implicitly has an 'any' type (string index on {})
(238,34): TS7053: Element implicitly has an 'any' type
(240,34): TS7053: Element implicitly has an 'any' type
(268,31): TS2339: Property 'app_id_replace' does not exist on type '{}'
(268,49): TS7005: Variable 'appID' implicitly has an 'any' type
(269,95): TS7005: Variable 'appID' implicitly has an 'any' type
(273,29): TS7053: Element implicitly has an 'any' type
(330,24): TS7006: Parameter 'event' implicitly has an 'any' type
(414,30): TS7006: Parameter 'e' implicitly has an 'any' type
(450,49): TS7005: Variable 'styles' implicitly has an 'any' type
(456,52): TS7053: Element implicitly has an 'any' type (displayMode index)
(458,48): TS7005: Variable 'styles' implicitly has an 'any' type
(520,60): TS7053: Element implicitly has an 'any' type
(521,21): TS7006: Parameter 'e' implicitly has an 'any' type
(644-1964): ~140 more errors, mostly TS7005 for 'styles' and 'sharedStrings' variables
(1788,5): TS2564: Property '#messagingContext' has no initializer
(1792,16): TS7006: Parameter 'args' implicitly has an 'any' type
(1823-1867): TS7053/TS2339 on config entity indexing
(1894-1950): TS7005 for 'afterPageLoadResolver' and 'readyToDisplayPlaceholdersResolver'
(1905,13): TS2721: Cannot invoke possibly null
(1911,13): TS2721: Cannot invoke possibly null
(1921,12): TS7006: Parameter 'message' implicitly has an 'any' type
(1963-1964): TS7005 for 'config'
```

## Fix Patterns

- **Module-level variables**: Add `/** @type {X | undefined} */` where `X` is derived from usage. For `styles`, trace to where it's populated from config.
- **TS2564**: Use `/** @type {X} */ (#prop)` or add definite assignment `!` in declaration.
- **TS2339 on Object**: Define proper `@typedef` for the config/entity shapes.
- **TS2322 (HTMLIFrameElement vs union)**: Widen parameter to `HTMLElement | HTMLIFrameElement`.
- **TS2683 (this)**: Convert to arrow function or add `@this {Type}`.
- **TS2721**: Guard with `if (resolver) resolver()`.

## Workflow

1. `npm ci`
2. Add both files to CORE_FILES in `scripts/check-strict-core.js`
3. Fix errors — start with the `styles` and `sharedStrings` typedefs to eliminate bulk errors
4. `npm run tsc-strict-core` — must pass
5. `npm run test-unit` — must pass
6. `npm run lint` — must pass (run `npm run lint-fix` first if needed)
7. Commit: `fix(types): add strict checking for click-to-load files`
8. `git push -u origin cursor/strict/click-to-load`

## Constraints

- Do NOT use `any` — use `unknown`, specific types, or proper interfaces
- Do NOT use `@ts-ignore` or `@ts-expect-error`
- Do NOT modify files outside the assigned list (except `scripts/check-strict-core.js`)
- Do NOT remove existing CORE_FILES entries
- Preserve existing behavior — type fixes only, no logic changes
Loading
Loading