Scope a JavaScript to Strict TypeScript Codex Task

Generate a precise execution prompt for OpenAI Codex to migrate legacy JavaScript files to strict TypeScript with zero any types and test verification.

Agent prompt for ChatGPT

You get: Task Overview, constraints Checklist and codex Directive

Prompt

Prompt
Act as a principal TypeScript engineer writing a scoped task file for OpenAI Codex.

I will paste the legacy JavaScript code or describe the target module right after this prompt.

Your job is to generate an execution prompt for Codex that guides it to convert the file to strict TypeScript without modifying business logic.

Rules for the generated Codex prompt:
1. Rename the file from .js to .ts and enforce strict mode.
2. Ban the 'any' keyword completely; require explicit interfaces or generics for all function arguments and returns.
3. Keep internal function bodies untouched unless an explicit type narrowing check is required.
4. Mandate a verification step using a project typecheck command (e.g., npx tsc --noEmit) before completing the task.

Output format:
- Task Overview: One line stating the exact input and output file paths.
- Constraints Checklist: Bullet list of strict typing boundaries Codex must respect.
- Codex Directive: The copy-paste block of instructions for Codex CLI or AGENTS.md.
- Verification Command: The shell command Codex must run to confirm zero type errors.

State one runtime risk involving dynamic object mutations that static types cannot catch.

Example output

Codex migration: auth-session.js to TypeScriptSections of the generated execution prompt
  1. Task OverviewStep 1Convert auth-session.js to .ts with boundary typing
  2. Constraints ChecklistStep 2Ban any, define interfaces, keep parsing logic, use readonly
  3. Codex DirectiveStep 3Add interfaces and signatures, no ts-ignore, keep exports
  4. Verification CommandStep 4npx tsc --noEmit --project tsconfig.json

Example for: migrating an un-typed user authentication session utility (auth-session.js).

Task Overview

Convert src/utils/auth-session.js to src/utils/auth-session.ts with complete boundary typing.

Constraints Checklist
  • Ban the any type; use unknown with type guards if incoming payloads are unstructured.
  • Define clear interfaces for UserSession, TokenPayload, and SessionConfig.
  • Do not rewrite internal token parsing logic or change runtime error throws.
  • Mark immutable session properties as readonly.
Codex Directive

Refactor src/utils/auth-session.js to src/utils/auth-session.ts following strict TypeScript rules:

  1. Create explicit interfaces: UserSession (id: string, email: string, roles: string[], expiresAt: number) and SessionValidationResult (valid: boolean, reason?: string).
  2. Add parameter and return type signatures to parseToken(), validateSession(), and buildSessionHeader().
  3. Do not introduce any or ts-ignore comments. If a payload property is uncertain, type it as unknown and validate with a typeof check.
  4. Preserve exact exported function signatures so downstream JavaScript consumers do not break.
Verification Command

npx tsc --noEmit --project tsconfig.json

Runtime risk: Dynamic runtime property deletions (such as delete session.user) will not trigger TypeScript compilation errors if the interface marks them as optional, which may introduce silent runtime bugs.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Strictly bans the any keyword to stop Codex from creating loose or meaningless type definitions.
  • Limits refactoring to function boundaries to prevent Codex from unintentionally altering working business logic.
  • Includes a deterministic CLI validation command so Codex can verify its work before terminating.

Paste your legacy JavaScript code snippet directly below the prompt in ChatGPT or Codex CLI to get an automated, risk-contained migration specification.

Common edits

  • Swap the verification command to pnpm typecheck or your custom monorepo build script.
  • Specify existing shared types Codex should import instead of creating local interfaces.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Codex

Optimize Cursor Workspace Context for AI Agents

Analyze your project directory to identify non-essential files and generate a precise .cursorignore file that keeps context windows clean and efficient.

Reconcile OpenAPI Schema Drift with Backend Logic

Get a three-column alignment matrix that identifies discrepancies between your OpenAPI spec, TypeScript client types, and actual backend request validation logic.

AI Coding AgentsClaude Code

Create a Legacy Module Reference Sheet for Coding Agents

Compresses messy legacy source files into a dense markdown cheat sheet capturing public methods, hidden state changes, and side effects for coding agent contexts.

Debug Regex and Parsers with GitHub Copilot

Generate an automated audit of regular expressions or parser snippets that flags catastrophic backtracking, isolates edge cases, and produces unit test fixtures.

Simple HTML Games

Build a Color Sequence Memory Game with Synth Tones in One HTML File

A ready-to-paste prompt that builds Echo Garden, a four-pad color-and-shape sequence memory game with Web Audio tones, a strict mode and rising speed.

Mini Apps & Tools

Build a Countdown Timer to Any Date With a Confetti Finish in One HTML File

Get a polished single-file countdown page with a custom event title, a large days-hours-minutes-seconds display and a confetti-and-chime celebration at zero.