Skip to main content

SKY-E004 · Dead code

Unnecessary TypeScript/JavaScript export

Low

An export that no other project file uses. It covers a value used only inside its own file, a re-export entry (export { a } from "./a") that nothing requests, and an exported TypeScript type or interface that no file imports from its module, including one used only in its own file.

Languages
TypeScript, JavaScript
Turned on by
skylos . (every scan)
Quality gate
counted toward the gate limits (full and diff scans). Reported in unused_exports. Counts toward max_dead_code, which has no limit by default, so it only fails a gate where you set one.
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 unnecessary export widens a module's interface. Readers assume another file depends on it, so dead types and helpers survive refactors and keep their own dependencies alive.

What Skylos flags

src/cart.ts · TypeScriptReported on line 1
export interface LegacyCartLine {  sku: string;  qty: number;} export function cartTotal(prices: number[]): number {  return prices.reduce((sum, price) => sum + price, 0);}
src/main.ts · TypeScript
import { cartTotal } from "./cart"; console.log(cartTotal([1, 2]));
package.json · JSON
{"name": "shop-web", "private": true, "main": "src/main.ts"}

What Skylos leaves alone

src/cart.ts · TypeScript
export interface CartLine {  sku: string;  qty: number;} export function cartTotal(lines: CartLine[]): number {  return lines.reduce((sum, line) => sum + line.qty, 0);}
src/main.ts · TypeScript
import { cartTotal } from "./cart"; console.log(cartTotal([{ sku: "a", qty: 1 }]));

package.json: same as in the flagged example.

Why Skylos leaves it alone

CartLine is the parameter type of cartTotal, which another file imports. A type in the shape of a requested export stays exported so callers can name it.

How Skylos decides

  1. Builds the project's module demand: named, default, type-only and namespace-member imports, import("./m").T type references, re-exports and export * chains. A name is unnecessary when no file requests it from the module.
  2. Public modules stay silent: package.json main, module, types, exports, bin and browser targets, tool, framework and test entries, files named by path, index/main/cli at a package root, modules no file imports and modules consumed whole.
  3. A type stays silent when it is merged with a value of the same name, lives in a .d.ts file or a declare global/declare module block, or is named in the shape of a value export another file requests. A requested type does not keep the types it mentions.
  4. @public, @alpha, @beta and @alias JSDoc tags mark published API and are never reported; @internal gives no protection.
  5. Vue, Svelte and Astro component scripts, inline <script type="module"> blocks in HTML and MDX import/export statements are read as text and request their names like any importer. A part that does not parse (another script language, a syntax error, an MDX import() expression, a Marko template) holds back only the modules its text names. Only an unreadable consumer turns the check off.
  6. A wildcard export with only a types condition publishes each module's declarations: its type exports stay silent, its value exports are still checked. Files in __testfixtures__/__fixtures__ folders are test data and never reported.

How to fix it

Remove the unused type, or drop its export keyword when the file still uses it.

src/cart.ts · TypeScript · the fix, against the flagged file
Removed: export interface LegacyCartLine {Removed:   sku: string;Removed:   qty: number;Removed: }Removed:  export function cartTotal(prices: number[]): number {  return prices.reduce((sum, price) => sum + price, 0);}

When it can be wrong

  • Code outside the scanned project (another repository, a code generator that reads types by name) can consume an export Skylos cannot see.

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

  • Add // skylos: ignore[SKY-E004] on the export's line.

  • Set [tool.skylos] ignore = ["SKY-E004"] to disable this rule project-wide.

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