Skip to main content

SKY-T106 · Quality, structure and performance

Unsafe exported API type

Medium

any switches TypeScript's checks off for a value. SKY-T106 reports any, an any-valued index signature and Record<string, any> in the types of what a module exports: function parameters and return types, interface and class members, type aliases and exported variables.

Languages
TypeScript
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

An exported type is a promise to every caller. With payload: any, each caller can read any property without a check, so a typo or a changed webhook format compiles fine and fails only in production, in code far from the module that let it through.

What Skylos flags

src/webhooks/types.ts · TypeScriptReported on line 4
export interface WebhookEvent {  id: string;  type: string;  payload: any;} export function handleWebhook(event: WebhookEvent): void {  console.log(event.id, event.type);}

What Skylos leaves alone

src/webhooks/types.ts · TypeScript
export interface WebhookEvent {  id: string;  type: string;  payload: unknown;} function logRaw(value: any): void {  console.log(JSON.stringify(value));} export function handleWebhook(event: WebhookEvent): void {  logRaw(event.payload);}

Why Skylos leaves it alone

The exported interface uses unknown, which forces every caller to check the payload before using it. The remaining any belongs to a helper that is not exported, so it is not part of the module's API.

More languages

TypeScript

Flagged

src/webhooks/handler.ts · TypeScriptReported on line 3
import type { WebhookEvent } from "./types"; export function handleWebhook(event: WebhookEvent, meta: Record<string, any>) {  console.log(event.id, meta.source);}

Not flagged

src/webhooks/handler.ts · TypeScript
import type { WebhookEvent } from "./types"; type Meta = { source: string; receivedAt: number }; export function handleWebhook(event: WebhookEvent, meta: Meta) {  console.log(event.id, meta.source);}

Why Skylos leaves it alone

The metadata has its own precise type, so the exported signature says exactly what callers must pass.

How Skylos decides

  1. Runs with --quality on .ts, .tsx, .mts and .cts files, declaration files (.d.ts) included. Generated files and files that do not parse are skipped.
  2. Collects what the module exports: exported functions, classes, interfaces, type aliases and variables, including export { name } lists and export default. Private class members are left out.
  3. Reads the type annotations of that public surface: parameters, return types, properties, index signatures and alias bodies.
  4. Reports a type that is exactly any (also as the value of an index signature) and Record<string, any> when Record is the built-in one. any nested inside another type, such as any[] or Promise<any>, is not reported.
  5. Reports MEDIUM on the line of the offending type, once per type.

How to fix it

Give the value a precise type. When its shape is not known in advance, use unknown, which makes each caller check it before use.

src/webhooks/types.ts · TypeScript · the fix, against the flagged file
Added: export type WebhookPayload =Added:   | { kind: "order.paid"; orderId: string; amount: number }Added:   | { kind: "order.refunded"; orderId: string; reason: string };Added:  export interface WebhookEvent {  id: string;  type: string;Removed:   payload: any;Added:   payload: WebhookPayload;} export function handleWebhook(event: WebhookEvent): void {  console.log(event.id, event.type);}

When it can be wrong

  • A deliberately generic API, such as a logger that accepts anything, is reported; unknown usually works there too.
  • It misses any nested inside another type (any[], Promise<any>, Map<string, any>) and any in code that is not exported.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • On the reported line:

    TypeScript
    payload: any; // skylos: ignore[SKY-T106] shape varies per provider
  • [tool.skylos] ignore = ["SKY-T106"] in pyproject.toml turns the rule off for the project. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.