Skip to content

DeepOmit

自 1.1.0 起

移除嵌套路径处的属性。

签名

typescript
type DeepOmit<T, P extends string> = T extends object
  ? P extends ''
    ? T
    : DeepOmitBySegments<T, PathSegments<T, P>>
  : T

参数

参数描述
T目标对象类型
P要移除的路径

描述

从对象类型中移除指定嵌套路径处的属性。

示例

基本用法

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

interface User {
  profile: {
    name: string
    email: string
    settings: {
      theme: string
      lang: string
    }
  }
}

type WithoutSettings = DeepOmit<User, 'profile.settings'>
// { profile: { name: string; email: string } }

单个属性

typescript
interface Config {
  database: {
    host: string
    port: number
    password: string
  }
}

type SafeConfig = DeepOmit<Config, 'database.password'>
// { database: { host: string; port: number } }

相关

  • DeepPick - 仅保留指定路径
  • Omit - TypeScript 内置 Omit

基于 MIT 许可发布