Skip to content

Detect unsafe TypeScript type assertions, including double assertions #22

Description

@CodeDeficient

Problem

KarpeSlop does not currently report unsafe TypeScript as assertions such as:

value as unknown as Target
value as Target

This is related to the previously closed #10, but the gap is broader: double assertions and ordinary unchecked object/array assertions can bypass structural type safety at database and external-data boundaries without any warning in strict mode.

Expected behavior

Strict analysis should report unsafe TypeScript assertions, including:

  • value as unknown as Target
  • Unchecked object assertions such as value as Record<string, unknown>
  • Unchecked array or domain-row assertions such as data as EventRow[]

The report should include the file, line, assertion form, and severity.

Scope boundaries

  • Do not report satisfies expressions as assertions.
  • Avoid false positives for generated declaration files and framework-required boundary declarations where possible.
  • Preserve the existing any and unsafe-type detectors.

Reproduction

interface EventRow {
  id: string;
}

const value: unknown = getExternalData();
const rows = value as unknown as EventRow[];
const record = value as Record<string, unknown>;

Neither assertion form was reported by npx karpeslop@latest --quiet --strict in the consuming project. Please add fixtures and regression tests for these patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions