Get IntelliSense for Cosmos DB Stored Procedures in VS Code: A 2026 Guide
Learn how to enable IntelliSense for Cosmos DB stored procedures in VS Code, providing type definitions and enhancing your coding productivity in 2026.
Get IntelliSense for Cosmos DB Stored Procedures in VS Code: A 2026 Guide
As a developer working with Azure Cosmos DB, you often need to write and manage stored procedures using the server-side JavaScript runtime. However, one common issue is the lack of IntelliSense support in Visual Studio Code (VS Code) for the Cosmos DB APIs. This tutorial will guide you through setting up IntelliSense, providing you with type definitions and documentation for a more efficient coding experience.
Key Takeaways
- Learn how to set up IntelliSense for Cosmos DB stored procedures in VS Code.
- Understand the server-side JavaScript context and its importance.
- Utilize type definitions to enhance coding efficiency.
- Explore common issues and troubleshooting tips.
In this guide, we'll explore why having IntelliSense is crucial for developing robust stored procedures and how you can configure your VS Code environment to support it. Whether you're a seasoned developer or just beginning your journey with Cosmos DB, understanding this setup will greatly enhance your productivity.
Prerequisites
- Basic knowledge of JavaScript and TypeScript.
- Experience with Azure Cosmos DB and its server-side JavaScript runtime.
- Visual Studio Code installed on your machine.
- Node.js and npm installed for managing dependencies.
Step 1: Install TypeScript and Node.js
To enable IntelliSense for Cosmos DB, you need to have TypeScript and Node.js installed on your system. TypeScript provides static typing, which is essential for IntelliSense.
npm install -g typescriptVerify the installation by checking the version:
tsc --versionEnsure Node.js is also installed:
node -vStep 2: Set Up a New VS Code Project
Create a new directory for your Cosmos DB project and open it in VS Code:
mkdir cosmos-db-project
cd cosmos-db-project
code .Step 3: Install Cosmos DB Type Definitions
To provide IntelliSense with the necessary API information, you'll need to install type definitions specific to Cosmos DB. Although official definitions might not be available, community-supported types can be found.
Create a typings directory and add a cosmos.d.ts file:
// cosmos.d.ts
interface Context {
getCollection(): Collection;
getResponse(): Response;
}
interface Collection {
queryDocuments(link: string, query: string, options: object, callback: Function): void;
getSelfLink(): string;
}
interface Response {
setBody(body: any): void;
}
declare function getContext(): Context;Include these typings in your tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"baseUrl": "./",
"typeRoots": ["./typings"]
},
"include": ["src/**/*"]
}Step 4: Enable JavaScript IntelliSense in VS Code
Ensure that IntelliSense is enabled for JavaScript by configuring your VS Code settings. Add the following to your settings.json:
{
"javascript.implicitProjectConfig.checkJs": true,
"typescript.tsdk": "node_modules/typescript/lib"
}Step 5: Writing and Testing a Cosmos DB Stored Procedure
With IntelliSense configured, create a new JavaScript file in your src directory:
// src/storedProcedure.js
const ctx = getContext();
const collection = ctx.getCollection();
const selfLink = collection.getSelfLink();
collection.queryDocuments(selfLink, 'SELECT * FROM c', {}, (err, docs) => {
if (err) throw new Error('Error querying documents');
ctx.getResponse().setBody(docs);
});In VS Code, you should now see IntelliSense suggestions as you type, thanks to the type definitions you included earlier.
Common Errors/Troubleshooting
If IntelliSense is not working as expected, try the following:
- Check your
tsconfig.jsonfor correct paths. - Ensure the
cosmos.d.tsis included in thetypeRoots. - Restart VS Code to refresh the IntelliSense engine.
- Verify your JavaScript file is in the
srcdirectory specified intsconfig.json.
Frequently Asked Questions
Can I use TypeScript for Cosmos DB stored procedures?
While Cosmos DB stored procedures are executed in JavaScript, you can use TypeScript locally to benefit from type checking and IntelliSense.
What if I cannot find official type definitions?
Community-supported or custom type definitions can be used to provide IntelliSense for Cosmos DB APIs.
Do I need to deploy the type definitions to Azure?
No, type definitions are only for local development and do not need to be deployed to Azure.
Frequently Asked Questions
Can I use TypeScript for Cosmos DB stored procedures?
While Cosmos DB stored procedures are executed in JavaScript, you can use TypeScript locally to benefit from type checking and IntelliSense.
What if I cannot find official type definitions?
Community-supported or custom type definitions can be used to provide IntelliSense for Cosmos DB APIs.
Do I need to deploy the type definitions to Azure?
No, type definitions are only for local development and do not need to be deployed to Azure.