typescript
Seeded TypeScript defects — widen-then-assert, unjustified double assertions, unknown leaking past the boundary.
16 deliberate defects, each with a marker naming the rule in standards/ it breaks. It measures recall: how many of the defects the reviewer flags at their severity or higher. The pass condition is that all 4 BLOCKER defects are flagged.
Because each marker names a rule, the scorer also grades attribution. A reviewer that finds the bug but cites the wrong rule counts as caught, and separately as misattributed.
Running it
Nothing here is ever merged. Open a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together, wait for the automated review to finish, then score it.
seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>
Flags and output are on redline metrics.
The 16 defects
| Seed | Severity | Rule it violates | Defect |
|---|---|---|---|
| 1 | BLOCKER | typescript/widen-then-assert | known value widened to unknown, then asserted back to a different type |
| 2 | BLOCKER | core/unsafe-assertion | double assertion with no SAFETY justification |
| 3 | BLOCKER | core/escape-hatch-types | any where a concrete type works |
| 4 | BLOCKER | core/type-checker-suppression | type checker silenced with no explanation and no ticket |
| 5 | HIGH | typescript/unknown-return | function exposes unknown to every caller |
| 6 | HIGH | typescript/unknown-type-alias | alias hides the top type |
| 7 | HIGH | typescript/open-dictionary-value | open dictionary of unknown values |
| 8 | HIGH | typescript/object-parameter | parameter typed object |
| 9 | HIGH | typescript/reflect-dynamic-access | Reflect.get bypasses typed property access |
| 10 | HIGH | typescript/known-value-widening | annotation makes routes.contact type-check while being undefined |
| 11 | HIGH | typescript/unknown-parameter | unknown parameter on a function that is not the boundary parser |
| 13 | HIGH | typescript/module-mocking | module mock replaces the import graph instead of injecting the dependency |
| 14 | HIGH | typescript/reduce-accumulator-copy | accumulator copied on every iteration — quadratic |
| 12 | SUGGESTION | typescript/ad-hoc-typeof-narrowing | typeof narrowing in domain logic on a value that should be typed |
| 15 | SUGGESTION | typescript/filter-map-double-pass | filter then map makes two passes and an intermediate array |
| 16 | SUGGESTION | typescript/conditional-empty-spread | conditional property hidden behind an empty-object spread |
Scoring
The score reports BLOCKER recall, false positives, and rule attribution. The canary appends it to data/seed-scores.jsonl and fails the run if BLOCKER recall drops below 1.0 or the clean corpus attracts a false positive. Of the 16 defects here, 4 BLOCKER, 9 HIGH and 3 SUGGESTION — only the BLOCKER count is a pass condition.
Adding a defect
Add the code and one marker line above it. The format, and what scripts/validate.mjs checks, are on Seeded corpus.
Related
- The typescript standard — every rule these defects test.
- seed-canary.yml — runs this corpus every week.
- Telemetry & validation — where the scores end up.
The full file
// DO NOT MERGE — Redline validation seed.
// Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher,
// citing that rule id. Score with scripts/score-seeds.mjs.
interface Account {
id: string;
balance: number;
}
interface Handler {
(request: Request): Promise<Response>;
}
declare const home: Handler;
declare const about: Handler;
declare function fetchJson(url: string): Promise<string>;
// SEED 1 [BLOCKER] (typescript/widen-then-assert) known value widened to unknown, then asserted back to a different type
export function toAccount(user: { id: string; name: string }): Account {
const raw: unknown = user;
return raw as Account;
}
// SEED 2 [BLOCKER] (core/unsafe-assertion) double assertion with no SAFETY justification
export function coerceAccount(payload: Record<string, string>): Account {
return payload as unknown as Account;
}
// SEED 3 [BLOCKER] (core/escape-hatch-types) any where a concrete type works
export function total(accounts: any[]): number {
return accounts.reduce((sum, account) => sum + account.balance, 0);
}
// SEED 4 [BLOCKER] (core/type-checker-suppression) type checker silenced with no explanation and no ticket
// @ts-ignore
export const fallback: Account = { id: 1 };
// SEED 5 [HIGH] (typescript/unknown-return) function exposes unknown to every caller
export async function loadAccount(id: string): Promise<unknown> {
return JSON.parse(await fetchJson(`/accounts/${id}`));
}
// SEED 6 [HIGH] (typescript/unknown-type-alias) alias hides the top type
export type AccountPayload = unknown;
// SEED 7 [HIGH] (typescript/open-dictionary-value) open dictionary of unknown values
export const accountCache: Record<string, unknown> = {};
// SEED 8 [HIGH] (typescript/object-parameter) parameter typed object
export function describe(value: object): string {
return String(value);
}
// SEED 9 [HIGH] (typescript/reflect-dynamic-access) Reflect.get bypasses typed property access
export function readField(account: Account, field: string): number {
return Reflect.get(account, field);
}
// SEED 10 [HIGH] (typescript/known-value-widening) annotation makes routes.contact type-check while being undefined
export const routes: Record<string, Handler> = { home, about };
// SEED 11 [HIGH] (typescript/unknown-parameter) unknown parameter on a function that is not the boundary parser
export function formatBalance(balance: unknown): string {
return (balance as number).toFixed(2);
}
// SEED 12 [SUGGESTION] (typescript/ad-hoc-typeof-narrowing) typeof narrowing in domain logic on a value that should be typed
export function label(account: Account | string): string {
if (typeof account === 'string') return account;
return account.id;
}
// SEED 13 [HIGH] (typescript/module-mocking) module mock replaces the import graph instead of injecting the dependency
declare const vi: { mock(path: string): void };
vi.mock('./account-store');
// SEED 14 [HIGH] (typescript/reduce-accumulator-copy) accumulator copied on every iteration — quadratic
export const byId = (accounts: Account[]): Record<string, Account> =>
accounts.reduce((acc, account) => ({ ...acc, [account.id]: account }), {});
// SEED 15 [SUGGESTION] (typescript/filter-map-double-pass) filter then map makes two passes and an intermediate array
export const positiveIds = (accounts: Account[]): string[] =>
accounts.filter((account) => account.balance > 0).map((account) => account.id);
// SEED 16 [SUGGESTION] (typescript/conditional-empty-spread) conditional property hidden behind an empty-object spread
export const withNote = (account: Account, note?: string) => ({ ...account, ...(note ? { note } : {}) });