Skip to content

Migrating a TS file

Goal: Apply the TS→SJS rewrite checklist on a real module.

  1. Rename .ts.sjs.
  2. Fix banned constructs (anydynamic, enum→sum types).
  3. Run superjs migrate from-prototype if imports still point at prototype paths.
  4. Run superjs check until clean.

Full guide: Migration.

Example

// After migration — no any, no enum
type Role = Admin | Member

type User {
  name: string;
  role: Role;
}

function roleLabel(u: User): string {
  return match u.role {
    Admin => "admin",
    Member => "member",
  }
}

Open in playground

Key takeaways

  • Migrate leaf modules first.
  • Use the compat matrix for npm wrappers.
  • superjs migrate from-ts assists bulk moves.
Documentation