Copilot Shorts: TS Types

bobbyg603 (Updated: August 24, 2023)
Copilot Shorts: TS Types

Overview

This quick tip demonstrates how to automatically generate TypeScript type interfaces from JavaScript objects using GitHub Copilot Chat.

Requirements

To implement this tip, you’ll need:

  • Visual Studio Code Insider’s build
  • GitHub Copilot Chat
  • Copilot Nightly

Workflow

  1. Copy an object received from a fetch request
  2. Open Copilot Chat
  3. Ask: “Generate a TypeScript interface for this object”
  4. Copilot generates the corresponding interface

Note: Sometimes the chat interface may display a filtered response message, yet the actual generated code will be correct when pasted into the editor.

Benefits

This technique streamlines TypeScript development by automating interface generation, saving you time when working with API responses.

If you copy the response and paste it in your editor, you’ll notice it’s correct—even when the chat indicates content filtering.

Takeaway

This tip is especially valuable for developers frequently handling external data sources who need rapid type definitions without manual coding.

What other Copilot tips do you use for TypeScript? Share below!