This example demonstrates extending base interfaces with application-specific functions.
02-single-extension/
├── base.define.ts # Base/framework interfaces
└── define.ts # Application interfaces (extends base)
-
BaseServerFunctions: Framework-level server functions
ping()- Health checkgetServerTime()- Get server timestamp
-
BaseClientFunctions: Framework-level client functions
showError()- Display error messageshowSuccess()- Display success messagegetClientInfo()- Get client environment info
-
ServerFunctions extends BaseServerFunctions:
- Inherits:
ping(),getServerTime() - Adds:
getProduct(),createProduct(),listProducts()
- Inherits:
-
ClientFunctions extends BaseClientFunctions:
- Inherits:
showError(),showSuccess(),getClientInfo() - Adds:
onProductUpdated(),refreshProducts()
- Inherits:
bun run ../../index.ts ./define.tsThe generator will automatically:
- Read
define.ts - Follow the import to
base.define.ts - Resolve the interface inheritance
- Generate code for all functions from both base and derived interfaces
After generation, you'll have access to:
Client->Server calls (6 functions):
ping()(from base)getServerTime()(from base)getProduct()createProduct()listProducts()
Server->Client calls (5 functions):
showError()(from base)showSuccess()(from base)getClientInfo()(from base)onProductUpdated()refreshProducts()
import { io } from 'socket.io-client';
import {
ping, // from base
getServerTime, // from base
getProduct, // from app
handleShowError // from base
} from './client.generated';
const socket = io('http://localhost:3000');
// Call base functions
const pong = await ping(socket);
const time = await getServerTime(socket);
// Call app functions
const product = await getProduct(socket, 'prod-123');
// Handle base functions
handleShowError(socket, async (socket, error) => {
console.error('Server error:', error.message);
});- Code Reuse: Define common functions once in base interfaces
- Separation of Concerns: Framework vs application logic
- Maintainability: Update base functions in one place
- Type Safety: Full TypeScript support across the inheritance chain