Effective TypeScript and VS Code extension engineering for this repo - strict typing patterns, error handling, async/streams, disposables, activation, webview messaging, performance, packaging with webpack, testing with Mocha and vscode-test. Use when writing or reviewing extension-host or shared TypeScript.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Typescript Extension Engineering?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/afri-bit-typescript-extension-engineering)
---
name: typescript-extension-engineering
description: Effective TypeScript and VS Code extension engineering for this repo - strict typing patterns, error handling, async/streams, disposables, activation, webview messaging, performance, packaging with webpack, testing with Mocha and vscode-test. Use when writing or reviewing extension-host or shared TypeScript.
---
# TypeScript and VS Code extension engineering
## TypeScript
- `strict` on; no `any`. Model unknown input as `unknown` and narrow with user-defined type guards or a small schema validator at boundaries (webview messages, file input).
- Discriminated unions for protocols (`{ type: 'x'; ... }`) with exhaustive `switch` + `assertNever`.
- Branded or opaque types for units that must not mix (`Nanoseconds`, `CanId`, `ByteOffset`); `bigint` for 64-bit raw values and ns timestamps (JSON cannot carry bigint - serialise as string or split).
- Immutability by default (`readonly`, `ReadonlyArray`); pure functions in `core`.
- Errors: typed errors from `src/shared/errors/`, `catch (err: unknown)`, helpers in `errorUtils`; never swallow; add context (what, where, input id).
- Numbers: bit math on `number` is 32-bit signed - use `>>>`, masks, or `BigInt` for >= 32-bit fields; test sign extension explicitly.
## Async and streams
`async`/`await`; `AsyncIterable` for frame/log streams; `AbortSignal` for cancellation; bound concurrency; never fire-and-forget a promise without `.catch`. Do not `await` inside hot loops when batching is possible.
## VS Code specifics
- `activate` returns quickly; lazy-create heavy services; activation events specific (`onLanguage:dbc`, `onCustomEditor:`, `onCommand:`).
- Everything disposable goes into `context.subscriptions`. Event emitters disposed. Timers cleared on dispose.
- Webviews: `retainContextWhenHidden` only when needed (memory); CSP with nonce; `asWebviewUri`; restore state with `getState/setState` or re-send from host.
- Custom editor: `CustomTextEditorProvider`/document model, apply edits via `WorkspaceEdit` so undo/redo and dirty state work; handle external changes.
- Use `Logger` (output channel), not `console`. Respect `vscode.workspace.fs` for virtual workspaces where feasible; declare `capabilities` in `package.json` honestly.
- Settings via `contributes.configuration` with descriptions, defaults, and scope; read through one config module.
## Performance
Measure before optimising (`console.time` in dev, VS Code "Developer: Show Running Extensions"). Avoid O(n^2) over messages x signals; index by id. Virtualise large lists. Parse big files incrementally.
## Build and packaging
webpack bundle to `dist/extension.js`; externals only `vscode`; vendor SDKs bundled (see spec `cansub-adapter`). `.vscodeignore` keeps `.claude/`, `openspec/`, `docs/`, tests out of the `.vsix`.
## Testing
Unit: pure TS with `test/mocha-vscode-stub.cjs` shim. Integration: `@vscode/test-electron`. Prefer fakes over mocks; deterministic clocks; table-driven tests for bit-packing and parser cases.