TypeScript Setup
Basic Type Usage
Importing Types
import {
TourConfig,
TourStep,
CardProps,
TourContext,
BaseTourEvent,
OverlayStyles,
CardPositioning,
} from 'Tourista';Typing Tour Configurations
import { TourConfig } from 'Tourista';
// Method 1: Basic typing (less type inference)
const basicTour: TourConfig = {
id: 'welcome-tour',
steps: [
{
id: 'step1',
page: '/',
targetElement: '#button',
title: 'Welcome',
content: 'Get started here',
},
],
allowPageNavigation: true,
allowSkip: true,
};
// Method 2: Using 'as const satisfies' (recommended)
// Provides both type checking AND literal type inference
const advancedTour = {
id: 'welcome-tour',
steps: [
{
id: 'step1',
page: '/',
targetElement: '#button',
title: 'Welcome',
content: 'Get started here',
},
],
allowPageNavigation: true,
allowSkip: true,
} as const satisfies TourConfig;
// With 'as const satisfies', TypeScript knows:
// - The exact tour ID is 'welcome-tour' (not just string)
// - The exact step IDs are literals
// - Better type inference for ExtractStates and other utilitiesTyping Tour Steps
Real-World Usage Pattern
Using the Typed Tour
Advanced Type Patterns
Custom Card Component Types
Typing Configuration Options
Type-Safe Event Handling
Type Inference
Extracting State Types
Extracting Tour IDs
Best Practices
Common Patterns
Creating a Tour Module
Next Steps
Last updated