Blog>
Snippets

Initializing TanStack Config with TypeScript

Showcase the initialization process of TanStack Config in a TypeScript project, including defining the configuration schema.
import { defineConfig } from '@tanstack/config';

export const config = defineConfig({
  settings: {
    databaseUrl: 'https://example.com',
    port: 3000
  }
});
This piece of code demonstrates how to define and export a configuration using TanStack Config in a TypeScript project. The `defineConfig` function is imported from '@tanstack/config' and used to create a config object with a 'settings' property containing the application configuration.
import { config } from './path/to/config';

// Accessing configuration values
console.log(config.settings.databaseUrl);
console.log(config.settings.port);
Here, the previously defined configuration is imported from its file, and its properties are accessed. This illustrates how to use the configuration values, such as 'databaseUrl' and 'port', in the application.