TypeScript Types
TypeScript Types
Complete TypeScript type definitions and interfaces for the DeskForge Runtime SDK.
WindowConfig
Configuration interface for window initialization.
interface WindowConfig {
title?: string;
width?: number;
height?: number;
minWidth?: number;
minHeight?: number;
resizable?: boolean;
fullscreen?: boolean;
}Properties
| Property | Type | Optional | Description |
|---|---|---|---|
title | string | ✓ | Window title displayed in title bar |
width | number | ✓ | Initial window width in pixels |
height | number | ✓ | Initial window height in pixels |
minWidth | number | ✓ | Minimum window width in pixels |
minHeight | number | ✓ | Minimum window height in pixels |
resizable | boolean | ✓ | Whether the window can be resized |
fullscreen | boolean | ✓ | Start in fullscreen mode |
Example
import type { WindowConfig } from '@deskforge/runtime';
const config: WindowConfig = {
title: 'My App',
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
resizable: true,
fullscreen: false,
};AppConfig
Configuration interface for application initialization.
interface AppConfig {
name: string;
version: string;
author?: string;
}Properties
| Property | Type | Optional | Description |
|---|---|---|---|
name | string | ✗ | Application name |
version | string | ✗ | Application version (semver) |
author | string | ✓ | Application author or company |
Example
import type { AppConfig } from '@deskforge/runtime';
const config: AppConfig = {
name: 'My Desktop App',
version: '1.0.0',
author: 'Your Company',
};IPCMessage
Structure for IPC command messages.
interface IPCMessage {
command: string;
payload?: any;
}Properties
| Property | Type | Optional | Description |
|---|---|---|---|
command | string | ✗ | Command identifier |
payload | any | ✓ | Command data (must be JSON-serializable) |
Example
import type { IPCMessage } from '@deskforge/runtime';
const message: IPCMessage = {
command: 'save_file',
payload: {
path: '/path/to/file.txt',
content: 'Hello, World!',
},
};IPCResponse
Structure for IPC command responses.
interface IPCResponse {
success: boolean;
data?: any;
error?: string;
}Properties
| Property | Type | Optional | Description |
|---|---|---|---|
success | boolean | ✗ | Whether the command succeeded |
data | any | ✓ | Response data (if successful) |
error | string | ✓ | Error message (if failed) |
Example
import type { IPCResponse } from '@deskforge/runtime';
// Success response
const successResponse: IPCResponse = {
success: true,
data: { id: 123, name: 'John Doe' },
};
// Error response
const errorResponse: IPCResponse = {
success: false,
error: 'File not found',
};Complete Example
Here's a complete example using all the type definitions:
import type {
WindowConfig,
AppConfig,
IPCMessage,
IPCResponse
} from '@deskforge/runtime';
import { initWindow, initApp, sendCommand } from '@deskforge/runtime';
// Define custom types
interface User {
id: number;
name: string;
email: string;
}
interface SaveFilePayload {
path: string;
content: string;
}
// Configure window
const windowConfig: WindowConfig = {
title: 'My Desktop App',
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
resizable: true,
};
// Configure app
const appConfig: AppConfig = {
name: 'My Desktop App',
version: '1.0.0',
author: 'Your Company',
};
// Initialize
await initWindow(windowConfig);
await initApp(appConfig);
// Type-safe IPC
const user = await sendCommand<User>('get_user', { id: 123 });
console.log(user.name); // TypeScript knows this is a string
const savePayload: SaveFilePayload = {
path: '/path/to/file.txt',
content: 'Hello, World!',
};
const saved = await sendCommand<boolean>('save_file', savePayload);
if (saved) {
console.log('File saved successfully');
}Type Safety Tips
✓ Define Custom Interfaces
Create interfaces for your specific command payloads and responses for better type checking.
✓ Use Generic Type Parameters
Leverage TypeScript generics in sendCommand<T> for full type inference.
✓ Enable Strict Mode
Use "strict": true in your tsconfig.json for maximum type safety.
💡 Share Types
Consider sharing type definitions between your frontend and Tauri backend for consistency.