Skip to content

Config

自 1.5.0 起

Type-safe configuration container with a marker for configuration values.

签名

typescript
type Config<T = unknown> = {
  [key: string]: T
} & {
  __config?: true
}

参数

参数描述
TThe value type for configuration entries

示例

基本用法

typescript
import type { Config } from 'uni-types'

type AppConfig = Config<{
  port: number
  host: string
  debug: boolean
}>

const config: AppConfig = {
  port: 3000,
  host: '0.0.0.0',
  debug: false,
  __config: true
}

Nested Configuration

typescript
import type { Config } from 'uni-types'

type DatabaseConfig = Config<{
  host: string
  port: number
  username: string
  password: string
  database: string
  pool: {
    min: number
    max: number
  }
}>

const dbConfig: DatabaseConfig = {
  host: 'localhost',
  port: 5432,
  username: 'admin',
  password: 'secret',
  database: 'myapp',
  pool: { min: 2, max: 10 },
  __config: true
}

相关

基于 MIT 许可发布