A VS Code template for solving LeetCode problems in TypeScript.
ts-lc is an addon on top of the VS Code LeetCode extension. It provides a richer local TypeScript development environment while keeping the LeetCode extension responsible for interacting with LeetCode.
- Fork this repository.
- Clone it.
- Run:
pnpm install- Open the repository in VS Code.
- Install the recommended extensions.
- Configure the LeetCode extension to use the
srcdirectory as its workspace folder.
You can either set this manually through the extension or add the following to global settings.json
"leetcode.workspaceFolder": "...\\ts-lc\\src"
"leetcode.defaultLanguage": "typescript",Once configured, LeetCode problem files are created inside src.
This repository does not replace the LeetCode extension.
The extension handles:
- Signing in to LeetCode
- Pulling problems
- Creating problem files
- Running LeetCode test cases
- Submitting solutions
- Other LeetCode API interactions
Use this repository as the local development environment on top of the extension.
The repository recommends:
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"leetcode.vscode-leetcode",
"yoavbls.pretty-ts-errors",
"orta.vscode-twoslash-queries",
"wallabyjs.quokka-vscode"
]
}dbaeumer.vscode-eslint
Provides ESLint integration and diagnostics directly in VS Code.
esbenp.prettier-vscode
Provides formatting using the repository's Prettier configuration.
leetcode.vscode-leetcode
Critical to this template. Handles the actual interaction with LeetCode, including authentication, pulling questions, testing and submission.
yoavbls.pretty-ts-errors
Makes large and deeply nested TypeScript diagnostics easier to read.
orta.vscode-twoslash-queries
Allows TypeScript types to be inspected directly in the editor.
wallabyjs.quokka-vscode
Runs JavaScript/TypeScript expressions directly inside the file and displays runtime values inline.
Useful for quickly testing a function without creating a separate test file.
The local environment uses:
| Component | Version |
|---|---|
| TypeScript | 5.7.3 |
| Node.js | 22.14.0 |
| pnpm | 10.15.0 |
TypeScript targets ES2024 with:
--alwaysStrict
--strictBindCallApply
--strictFunctionTypes
--target ES2024
VS Code is configured to use the repository's local TypeScript installation:
"js/ts.tsdk.path": "node_modules\\typescript\\lib"The dependencies available to LeetCode solutions are pinned to exact versions.
"lodash": "4.17.21"LeetCode provides Lodash as _ globally. This repository therefore declares the global for TypeScript in global.d.ts:
import type lodash from "lodash";
declare global {
const _: typeof lodash;
}This allows:
_.isEqual(a, b);without importing Lodash in the solution.
The following versions are included:
@datastructures-js/binary-search-tree 5.4.0
@datastructures-js/deque 1.0.8
@datastructures-js/graph 5.3.1
@datastructures-js/heap 4.3.7
@datastructures-js/linked-list 6.1.4
@datastructures-js/priority-queue 6.3.5
@datastructures-js/queue 4.3.0
@datastructures-js/set 4.2.2
@datastructures-js/stack 3.1.6
@datastructures-js/trie 4.2.3
Documentation:
https://datastructures-js.info/docs
For Binary Search Tree, Trie, and Graph, import the package manually when required because some of their exported names can conflict with names used by LeetCode problems.
For example:
import h from "@datastructures-js/heap";
const { MinHeap } = h;or:
import bst from "@datastructures-js/binary-search-tree";
const { BinarySearchTree } = bst;MIT