An Azure NoSQL database service for app development.
Azure Cosmos DB stored procedures run inside a restricted server-side JavaScript environment that does not expose the normal JavaScript runtime, TypeScript types, or IntelliSense metadata. The server-side objects (getContext(), getCollection(), queryDocuments(), etc.) are injected by the Cosmos DB host and are not part of any standard JavaScript library. Because of this, VS Code cannot provide IntelliSense by default.
There is no official .d.ts file, npm package, or type definitions published by Microsoft for the server-side API. However, there are a few practical ways to improve the development experience.
1. Create your own .d.ts file
You can define the parts of the API you use most often. This enables basic IntelliSense in VS Code.
Example:
declare function getContext(): {
getCollection(): {
queryDocuments(
link: string,
query: string,
options: any,
callback: (err: any, docs: any[]) => void
): void;
};
getResponse(): {
setBody(body: any): void;
};
};
Place this file anywhere in your workspace and VS Code will pick it up.
2. Use a VS Code extension that provides Cosmos DB server-side IntelliSense
Some community extensions provide type definitions, snippets, and editor support for stored procedures, triggers, and UDFs.
One example is the Cosmos DB Toolkit, which provides:
- IntelliSense for server-side APIs
- Type definitions for
getContext(),getCollection(),queryDocuments(), etc. - Snippets for stored procedures, triggers, and UDFs
- A scratchpad for testing server-side JavaScript
VS Code Marketplace:
https://marketplace.visualstudio.com/items?itemName=WayneBlackmon.cosmosdb-toolkit
GitHub repository:
https://github.com/wayne-blackmon/cosmosdb-toolkit
3. Develop stored procedures in normal JS/TS and deploy separately
Many teams write and test logic in TypeScript (with their own types), then compile and paste the final JavaScript into Cosmos DB. This provides full IntelliSense during development.
Summary:
Cosmos DB does not ship IntelliSense or type definitions for its server-side JavaScript runtime. You can create your own .d.ts file, use a community extension that provides type definitions, or develop in TypeScript and deploy compiled JavaScript. These approaches give you IntelliSense support while working with Cosmos DB stored procedures in VS Code.