#407 VSCode Extensions with Typescript
An initial exploration of writing vscode extensions with Typescript.
Notes
VS Code extensions are just Node.js packages that plug into the editor’s extensibility API.
With TypeScript you get type-safe access to that API, compile-time checks and first-class tooling.
The fastest way to start is to scaffold a project with the official Yeoman generator (yo code), choose “New Extension (TypeScript)”, and press F5 to launch a second VS Code window that already loads your extension for live debugging .
Key moving parts
src/extension.ts– entry file; export anactivate()(and optionallydeactivate()) function.package.json– lists metadata, activation events and the commands your extension contributes.vscodemodule – gives you APIs for commands, editors, diagnostics, webviews, Language Server Protocol, etc.- Extension Development Host – special VS Code instance spawned by F5 where your code runs; reload it with Ctrl-R to pick up changes.
Typical flow
- Run
yo code, pick TypeScript, name it, open the folder. - Open
src/extension.ts, register a command withvscode.commands.registerCommand. - Add the command id to the
commandsandactivationEventsarrays inpackage.json. - Press F5 → new window opens → Cmd-Shift-P → run your command → see the info message.
- Iterate: edit, reload window, test.
- When ready,
vsce package(orvsce publish) to share the extension .
That’s it—about 20 lines of TypeScript give you a working command, and from there you can add language support, tree views, webviews, task providers, debug adapters, etc.
The First Tutorial
Following along with https://code.visualstudio.com/api/get-started/your-first-extension …
Installing the generator
npm install --global yo generator-code
Running the generator:
$ yo code
# ? What type of extension do you want to create? New Extension (TypeScript)
# ? What's the name of your extension? HelloWorld
### Press <Enter> to choose default for all options below ###
# ? What's the identifier of your extension? helloworld
# ? What's the description of your extension? LEAVE BLANK
# ? Initialize a git repository? Y
# ? Which bundler to use? unbundled
# ? Which package manager to use? npm
# ? Do you want to open the new folder with Visual Studio Code? Open with `code`
The key generated components:
Running the extension:

What Next
- Testing
- a core part of the extension framework
- Publishing checklist:
vsceCLI installed (npm i -g vsce).package.jsonhasname,version,publisher,engines.vscode,repositoryand aREADME.md.- Create a publisher ID once at marketplace.visualstudio.com → “Publish extensions”.
- Generate a Personal Access Token (Pubs > Manage > Tokens) with
Marketplacescope. vsce login(paste token) →vsce publish(orvsce packageto get a.vsixto side-load).- Done: extension is live in the Marketplace within a few minutes.