Playground API
DocsStatsBlogStudio
Documentation Tree
Technical BlogFeature Deep Dives
  • Introduction
  • Quickstart
    5 min
  • How It Works
  • Recipes & Cookbooks
  • Platform Comparisons
  • Real-World Showcase
  • Interactive Studio
    Studio
  • GraphiQL IDE
    IDE
  • Session Quotas & Activity
  • Network Chaos Simulator
  • Atomic Sandbox Reset
  • Overview & Models
    Hub
  • Users Resource
  • Posts Resource
  • Comments Resource
  • Todos Resource
  • Custom Collections
    Custom
  • Multipart File Uploads
    Upload
  • Dynamic SVG Avatars
    SVG
  • Image Thumbnails
    CDN
  • Relational Filtering
  • Full-Text Search
  • Dynamic Sorting
  • Offset Pagination
  • Cursor Pagination
    Scroll
  • CSV & Excel Export & Import
    IO
  • Custom Collections
    CRUD
  • Overview & Architecture
    Hub
  • JWT Auth Flow
  • Refresh Token Rotation
    Mutex
  • RBAC Permission Matrix
    Roles
  • Expiry Simulation
  • Clock Skew Drift
  • Password Recovery Loop
  • Dual-Mode Sandboxing
  • GraphiQL IDE
    IDE
  • Relational Queries
  • Stateful Mutations
  • Realtime Subscriptions
  • Overview & Flowcharts
    Hub
  • Hosted Checkout
    Stripe
  • Payment Intents API
  • 3DS Challenge Modal
    Modal
  • Customers Vault
  • Charges & Refunds
  • Test Cards Catalog
  • Overview & Channels
    Hub
  • Virtual Email Mailbox
    Mailtrap
  • Virtual SMS Terminal
    Phone
  • In-App Notifications
  • Message Dispatcher
  • Realtime Studio
    Studio
  • Native WebSocket (/ws)
  • Socket.io Gateway
  • Presence & Echo Bot
  • Server-Sent Events (SSE)
    SSE
  • Analytics Telemetry
  • Webhook Subscriptions
  • HMAC SHA-256 Signatures
  • Delivery Logs
  • Manual Retry Simulator
  • Network Latency Delay
  • HTTP Status Codes
  • Rate-Limit Simulator
    429
  • Flaky Network & Jitter
    Chaos
  • Session Quotas & Activity
  • JSON Snapshots
    JSON
  • Headless CI/CD Testing
    CI
  • Mobile QR Code Sync
  • System Metrics & Health
  • Atomic Sandbox Reset
  • Official TypeScript SDK
  • Multi-Language Generators
  • DevTools Extension
  • OpenAPI 3.1 Spec
    JSON
  • Postman Collection v2.1
  • Bruno Collection
  • Insomnia Workspace
  • TypeScript .d.ts
    .d.ts
  • AI Prompt Rules
    Rules
  • Context Index (llms.txt)
  • Full Schema (llms-full.txt)
  • Manifest (product.json)
  • All Feature Articles
    Blog
  • React CRUD Without Backend
    Deep Dive
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE Guide
Technical Blog
Articles

In-depth articles explaining stateful mock APIs, WebSockets, payments, and frontend resilience.

Read Articles
PreviousInsomnia Workspace
NextAI Prompt Rules
Client Collections

TypeScript Ambient Declarations (.d.ts)

Get complete IntelliSense, strict type inference, and compile-time validation across your entire frontend codebase without installing any third-party npm packages.

TypeScript .d.tsplayground-api.d.ts

Official Ambient Type Definitions

Contains all model interfaces (User, Post, Comment, Todo, PaymentIntent), request filters, and pagination envelopes under the global PlaygroundApi namespace.

Download playground-api.d.ts

Installation in Next.js, React, or Vite

Place the downloaded playground-api.d.ts into your project's types/ directory and ensure your tsconfig.json includes it:

tsconfig.json
1
{
2
"compilerOptions": {
3
"target": "ES2022",
4
"lib": ["DOM", "DOM.Iterable", "ESNext"],
5
"strict": true,
6
"moduleResolution": "bundler"
7
},
8
"include": [
9
"src",
10
"types/**/*.d.ts" // Recognizes playground-api.d.ts automatically
11
]
12
}

Using Ambient Types in React Components

No imports necessary — your editor will automatically autocomplete properties and validate response envelopes:

BlogFeed.tsx
1
// Global types are available without any import statement!
2
import { useState, useEffect } from 'react';
3
4
export function BlogFeed() {
5
// 1. Strongly typed state using PlaygroundApi namespace
6
const [posts, setPosts] = useState<PlaygroundApi.Post[]>([]);
7
const [pagination, setPagination] = useState<PlaygroundApi.PaginationMeta | null>(null);
8
const [loading, setLoading] = useState(true);
9
10
useEffect(() => {
11
async function loadData() {
12
const res = await fetch('https://playground.nileslabs.com/api/v1/posts?_limit=5', {
13
credentials: 'include',
14
});
15
16
// 2. Strongly typed JSON response envelope
17
const json: PlaygroundApi.PaginatedResponse<PlaygroundApi.Post> = await res.json();
18
setPosts(json.data);
19
setPagination(json.pagination);
20
setLoading(false);
21
}
22
loadData();
23
}, []);
24
25
if (loading) return <p>Loading articles...</p>;
26
27
return (
28
<div>
29
<h2>Blog Feed ({pagination?.total} total)</h2>
30
{posts.map((post) => (
31
<article key={post.id}>
32
<h3>{post.title}</h3>
33
<p>{post.body}</p>
34
</article>
35
))}
36
</div>
37
);
38
}

Namespace Interface Preview

A glance at the definitions provided inside the ambient namespace:

playground-api.d.ts
1
declare namespace PlaygroundApi {
2
export interface Post {
3
id: number;
4
title: string;
5
body: string;
6
userId: number;
7
tags?: string[];
8
createdAt?: string;
9
updatedAt?: string;
10
}
11
12
export interface User {
13
id: number;
14
name: string;
15
username: string;
16
email: string;
17
address: {
18
street: string;
19
suite: string;
20
city: string;
21
zipcode: string;
22
geo: { lat: string; lng: string };
23
};
24
phone: string;
25
website: string;
26
company: {
27
name: string;
28
catchPhrase: string;
29
bs: string;
30
};
31
}
32
33
export interface PaginationMeta {
34
total: number;
35
page: number;
36
limit: number;
37
totalPages: number;
38
hasNextPage: boolean;
39
hasPrevPage: boolean;
40
}
41
42
export interface PaginatedResponse<T> {
43
data: T[];
44
pagination: PaginationMeta;
45
}
46
}

Want full method autocomplete with zero boilerplate?

Check out our official TypeScript SDK package for isomorphic data fetching and retries.

View TypeScript SDK