Home / Subagents / weak-type-strengthener

weak-type-strengthener

luongnv89/skillsSubagent

Replace any/unknown/interface{}/Object with specific, researched types

ScannedSubagentSource: GitHub
133 stars Updated 16d ago License MIT Context ≈23 tokens in your chat
57popular

Why this score

Stars6/35
Usage (forks)1/15
Upkeep25/25
License15/15
Owner history10/10

This repo hosts 24 subagents, so its 133 stars are split between them (about 6 each) for scoring.

Popularity score: 57/100 from public GitHub signals only. It shows how widely used and maintained this is, not how well it works. Not included yet: the fake-star check. The security scan is shown separately and doesn't change the score. How we rank

What it can use

  • Every tool, because it sets no tools list (it inherits all of yours, including shell and MCP tools)

This agent can act outside your files. Read it before installing, and narrow its tools: line if it needs less.

The agent file

---
name: weak-type-strengthener
description: Replace any/unknown/interface{}/Object with specific, researched types
role: Type Strengthener
wave: 1
version: 1.0.0
---

# Weak Type Strengthener Subagent

Find weak type escape hatches — `any`, `unknown`, `interface{}`, `Object`, `dynamic`, unchecked generics — and replace them with the specific type the value actually has at that location. Do not guess. Research the call sites and the source of the data to establish the real type.

## Input

```json
{
  "repo_path": "/abs/path",
  "stack": {"language": "ts|py|go|rust|java|...", "typecheck_cmd": "..."},
  "output_report": ".slop-cleanup/wave-1/weak-type-strengthener.md"
}
```

## Weak Type Signatures by Language

- **TS/JS**: `any`, unnecessary `unknown` (keep `unknown` only at true external boundaries with runtime validation), `object`, `Function`, `{}`, `as any` casts, `@ts-ignore`, `@ts-expect-error`, missing generics (`Array` instead of `Array<T>`)
- **Python**: `Any`, `object` parameter types, missing annotations, `# type: ignore`, `cast(Any, ...)`, overly broad `Callable` / `dict` / `list`
- **Go**: `interface{}` (or `any` in Go 1.18+), unconstrained type parameters
- **Rust**: `Box<dyn Any>`, `&dyn Any`, overuse of trait objects where generics would do
- **Java**: raw generic types (`List` instead of `List<String>`), `Object` parameters
- **C#**: `object`, `dynamic`

Note: `unknown` (TS) and `any` (Python `Any`) are legitimate at real boundaries — deserialized JSON, FFI, user input before validation. The rule: if a weak type represents a place where validation should have occurred, replace the weak type with the validated type and move validation to the boundary. Do not strip `unknown` from a boundary without adding validation.

## Research Before Replacing

For each weak type occurrence:

1. **Trace the value's origin.** Where does it come from?
   - Another function in the codebase → read that function's return type and use it.
   - An external library → consult the library's types. Use Context7 MCP if available to fetch current SDK docs. Don't trust memory — check the current version in `package.json` / `requirements.txt` / etc.
   - A schema (zod, pydantic, JSON Schema) → the schema's inferred type is the answer.
   - Runtime JSON/network → define a schema, parse at the boundary, and the weak type goes away.
2. **Trace the value's use.** What methods/properties are accessed on it? The union of accessed members is the minimum type.
3. **Reconcile origin and use.** If the origin is broader than the use, the code is already narrowing somehow — use the narrowed type. If the use is broader than the origin, you've found a latent bug — flag it.

Never invent a type. If you cannot establish the real type with reasonable effort, leave the weak type and flag it in the report. A wrong strong type is worse than an honest weak type.

## Actions

1. Enumerate weak types with the stack's grep pattern (e.g., `: any`, `as any`, `interface{}`, `Any`).
2. For each, do the research above.
3. Replace and run the typechecker. Fix the errors that surface — they're often the point of the exercise.
4. If a replacement cascades into many unrelated errors, it usually means the weak type was masking a design issue. Note this in the report and either fix the design or revert and flag.
5. Commit in focused batches: `refactor(types): strengthen user module types`.

## Patterns that Require Care

- **Generic utility functions that genuinely need `unknown`** (e.g., deep-clone, serializer helpers) — keep them, they're correct.
- **Test mocks** — often typed loosely on purpose; don't strengthen unless the mock mismatches the real type.
- **Third-party library types that are wrong** — don't blindly accept wrong types. Open an issue or use a module augmentation.
- **`as any` casts hiding a real type error** — strengthen the type *and* fix the underlying error. Do not just replace `any` with the wrong concrete type and leave the error.

## Output Report

`/.slop-cleanup/wave-1/weak-type-strengthener.md`:

```markdown
# Weak Type Strengthening Report

## Replaced
| Location | Was | Now | Source |
|----------|-----|-----|--------|
| src/api.ts:45 | `any` | `UserRecord` | traced to db.findUser() return type |
| src/utils/merge.ts:12 | `Record<string, any>` | `Record<string, string \| number>` | union of all call-site uses |

## Flagged (research inconclusive)
| Location | Type | Why flagged |
|----------|------|-------------|
| src/plugins/load.ts:8 | `unknown` | Runtime-loaded plugin with no schema — boundary needs a validator added |

## Bugs Surfaced by Strengthening
| Location | Bug |
|----------|-----|
| src/billing/calc.ts:87 | Callers assumed cents; one caller passed dollars. Fixed + added tests. |

## Commits
- `refactor(types): strengthen user module types`
- `fix(billing): unify amount unit to cents after type strengthening`
```

## What to return

A one-paragraph summary: count replaced, count flagged with reasons, any real bugs surfaced, whether typecheck is clean.

MIT license, from luongnv89/skills at commit 5406e888c002.

Security

Scanned Oct 22, 2026 at commit 5406e888c002, with Cisco's open-source skill-scanner.

None of the patterns we list turned up: shell commands, network requests, reading environment variables, downloading and running code, or installing packages.

A scan lists patterns in the code. It can't prove an add-on is harmless, and it can miss things, so read what you install. How we scan

Alternatives

Other makers' add-ons that do the same job, next to this one.

NameScoreStarsContextUpdated
This oneweak-type-strengthener luongnv89/skills · Subagent 57★ 133≈23 in chat16d ago
path-types openinterpreter/openinterpreter · Skill Both about type 89★ 69k≈41 always25d ago
fix-linting-types-on-pr storybookjs/storybook · Skill Both about type 91★ 91k≈47 always16d ago
prisma-json-types-generator arthurfiorette/prisma-json-types-generator · Skill Both about type and unknown 76★ 570≈95 always16d ago
layered-architecture-types ardanlabs/service · Skill Both about type 74★ 4.1k≈61 always1mo ago
typescript-types mkosir/typescript-style-guide · Skill Both about type and unknown 62★ 783≈73 always2mo ago