Blog>
Snippets

Defining Type-Safe Configuration Schemas

Demonstrate how to define a type-safe configuration schema using TypeScript interfaces or types for TanStack Config.
interface ConfigSchema {
  databaseUrl: string;
  port: number;
  enableLogging: boolean;
}
Defines a type-safe configuration schema using TypeScript interface. This schema dictates that the configuration object must have a 'databaseUrl' of type string, a 'port' of type number, and an 'enableLogging' boolean flag.
const config: ConfigSchema = {
  databaseUrl: 'https://example.com/database',
  port: 3000,
  enableLogging: true
};

export default config;
Creates a configuration object adhering to the ConfigSchema interface, ensuring type safety. This configuration specifies the database URL, the port number for the application, and whether logging is enabled.