TypeScript Setup
Tourista is built with TypeScript and provides comprehensive type definitions. This guide shows how to leverage TypeScript for better developer experience and type safety.
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
Here's how to set up a fully type-safe tour with helpers and exports:
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
Use
as const satisfies TourConfig: This pattern gives you both type checking and literal type inferenceExport typed hooks: Create tour-specific versions of
useTourfor better DXExport state types: Make
ExtractStates<typeof tourConfig>available for componentsOrganize tours in separate files: Keep each tour configuration in its own module
Use step-level options: Configure
canPrev,canSkipat the step level for fine control
Common Patterns
Creating a Tour Module
Next Steps
Explore Core Concepts for deeper understanding
Check API Reference for all available types
See Examples for real-world TypeScript usage
Last updated