Type Safety

The module generates TypeScript types from your schema, making useSafeRuntimeConfig() fully typed without manual generics.

How It Works

Your schema is converted to JSON Schema

JSON Schema is transformed to TypeScript types

Types are written to .nuxt/types/safe-runtime-config.d.ts

useSafeRuntimeConfig() returns a typed object

useSafeRuntimeConfig vs useRuntimeConfig

ComposableTypesValidation
useRuntimeConfig()Partial, manualNone
useSafeRuntimeConfig()Auto-generated from schemaBuild + Runtime (opt-in)
// useRuntimeConfig() - types may not match actual values
const config = useRuntimeConfig()
config.public.apiBase // unknown or manually typed

// useSafeRuntimeConfig() - types inferred from schema
const config = useSafeRuntimeConfig()
config.public.apiBase // string (from your schema)

Type Inference

Types are inferred from your schema's structure:

// Schema
const schema = object({
  public: object({
    apiBase: string(),
    count: optional(number()),
  }),
  secretKey: string(),
})

// Generated type
interface SafeRuntimeConfig {
  public: {
    apiBase: string
    count?: number
  }
  secretKey: string
}

Server vs Client

On the server, you get the full config. On the client, only public properties are available:

// Server
const config = useSafeRuntimeConfig()
config.secretKey // available

// Client
const config = useSafeRuntimeConfig()
config.secretKey // undefined (private keys not exposed)
config.public.apiBase // available

Generated Types Location

Types are stored in .nuxt/types/safe-runtime-config.d.ts and automatically included via Nuxt's type augmentation.

Run nuxi prepare to regenerate types after schema changes.