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

PropertyTypeOptionalDescription
titlestring✓Window title displayed in title bar
widthnumber✓Initial window width in pixels
heightnumber✓Initial window height in pixels
minWidthnumber✓Minimum window width in pixels
minHeightnumber✓Minimum window height in pixels
resizableboolean✓Whether the window can be resized
fullscreenboolean✓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

PropertyTypeOptionalDescription
namestring✗Application name
versionstring✗Application version (semver)
authorstring✓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

PropertyTypeOptionalDescription
commandstring✗Command identifier
payloadany✓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

PropertyTypeOptionalDescription
successboolean✗Whether the command succeeded
dataany✓Response data (if successful)
errorstring✓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.