# @brixtol/tsutils 中文文档

规范地址：https://npmcn.com/package/%40brixtol/tsutils/

版本：1\.4\.1
npm 元数据更新时间：2022-04-04T20:43:56.746Z
中文译文更新时间：2026-11-08T15:42:44.528Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40brixtol/tsutils
原文对照：https://npmcn.com/package/%40brixtol/tsutils/?lang=original
项目主页：https://github.com/BRIXTOL/tsutils
源码仓库：https://github.com/brixtol/tsconfig

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：26.5 kB，25 个文件
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2021-11-06T10:48:14.192Z
- 最新版本发布：2021-11-14T01:47:41.157Z
- 近 30 天下载量：9068（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：6（近 12 个月 0 个）

## 中文简介

常用的纺织品类型

## 安装

```sh
npm install @brixtol/tsutils
```

也可以使用：`pnpm add @brixtol/tsutils`、`yarn add @brixtol/tsutils`、`bun add @brixtol/tsutils`

## README

# @ brixtol/ tsutils

文本工具类型 [Brixtol 纺织品公司](https://brixtoltextiles.com/) 单曲工作空间。 这个模块基于松散的 [类型庆典](https://github.com/sindresorhus/type-fest) 意思是提供了一些必要的类型.

### 安装

[小时](https://pnpm.js.org/en/cli/install)

```cli
pnpm add @brixtol/tsutils

```

# 使用量

通过命名空间导入模块 。 下面的例子显示了一些公用事业。 附加上下文请查看 [测试](https://github.com/BRIXTOL/tsutils/tree/master/test) 目录.

```ts
import { AnyCase, ArrayMin, ConcatUnion } from '@brixtol/tsutils';

let string: AnyCase<'foo'>; // 'FOO' | 'FoO' | 'fOO' etc etc

let concat: ConcatUnion<'A' | 'B', '-'>; // 'A' | 'B' | 'A-B' etc etc

let arrmin: ArrayMin<2, string>; // ['a', 'b']

// etc etc
```

# 公用事业

该套件提供了多套有用的TypeScript工具. 如果你需要更多,请看 [类型庆典](https://github.com/sindresorhus/type-fest)下面是所包括的内容以及如何使用这些内容的一些基本例子.

#### `AnyCase<string>`

将字符串结合转换为 AnyCase 组合,

```ts
const anycase: AnyCase<'foo'> = (
  | 'FOO'
  | 'fOO'
  | 'foO'
  | 'Foo'
  | 'FOo'
  | 'foo'
  | 'fOo'
  | 'FoO'
);
```

#### `ArrayFixed<number, type>`

确保一个阵列有固定的长度,因为它不能比所提供的长度多或少.

```ts
// ✓ VALID
const a: ArrayFixed<2, string> = ['A', 'B'];
const b: ArrayFixed<3, string> = ['A', 'B', 'C'];

// 𐄂  INVALID
const c: ArrayFixed<2, string> = ['A'];
```

#### `ArrayMax<number, type>`

确保数组的长度最大 。 如果数组的大小超过长度,则会抛出错误.

```ts
// ✓ VALID
const a: ArrayMax<3, string> = ['A', 'B'];
const b: ArrayMax<4, string> = ['A', 'B', 'C'];

// 𐄂  INVALID
const c: ArrayMax<2, string> = ['A', 'B', 'C'];
```

#### `ArrayMin<number, type>`

确保数组类型具有最小长度。 如果数组的大小小于长度,则会抛出错误.

```ts
// ✓ VALID
const a: ArrayMin<2, string> = ['A', 'B'];
const b: ArrayMin<3, string> = ['A', 'B', 'C'];

// 𐄂  INVALID
const c: ArrayMin<2, string> = ['A'];
```

#### `ArrayRange<number, number, type>`

确保数组长度大于 `from` 大小和小于 `to` 尺寸.

```ts
// ✓ VALID
const a: ArrayRange<2, 4, string> = ['A', 'B'];
const b: ArrayRange<1, 3, string> = ['A', 'B', 'C'];

// 𐄂  INVALID
const c: ArrayRange<2, 4, string> = ['A'];
```

#### `ConcatUnion<union, separator>`

组合字符串联盟,包括来自联盟类型和自定义分隔符的值.

```ts
const union: ConcatUnion<'A' | 'B' | 'C', '-'> = (
  | 'A'
  | 'B'
  | 'C'
  | 'A-B'
  | 'B-A'
  | 'A-C'
  | 'B-C'
  | 'A-B-C'
  | 'B-A-C'
  | 'C-A'
  | 'C-B'
  | 'C-A-B'
  | 'C-B-A'
);

```

#### `Join<string, separator>`

使用给定的字符串作为分隔符加入一系列字符串和/或数字。 用于定义嵌入对象中的密钥路径 .

> 被从 [类型庆典](https://git.io/JX5eJ)

```ts
 // Mixed (strings & numbers) items; result is: 'foo.0.baz'
const path: Join<['foo', 0, 'baz'], '.'> = 'foo.0.baz';
 *
// Only string items; result is: 'foo.bar.baz'
const path: Join<['foo', 'bar', 'baz'], '.'> = 'foo.bar.baz'
 *
// Only number items; result is: '1.2.3'
const path: Join<[1, 2, 3], '.'> = [1, 2, 3].join('.');
```

#### `JoinProps<object, separator?>`

深层引用对象键生成字符串字形平整结合,带有选项分隔符字符,默认为 `.` 点.

```ts
const props: JoinProps<{
  a: string;
  b: {
    c: string;
    d: {
      e: {
        f: string;
        g: string;
      }[];
    }
  }
> = (
  | "a"
  | "b"
  | "b.c"
  | "b.d.e"
  | "b.d"
  | `b.d.e.${number}.f`
  | `b.d.e.${number}.g`
  | `b.d.e.${number}`
)

```

#### `LiteralUnion<union>`

允许通过字符串类型,同时尊重intellisense补全.

```ts
const literal: LiteralUnion<'A' | 'B'> = (
  | 'A'
  | 'C'
  | 'D' // D is allowed to pass
)
```

#### `Merge<object, object>`

将两种类型合并为新类型。 第二类密钥会覆盖第一类密钥.

> 被从 [类型庆典](https://git.io/JX5ua)

```ts
type Foo = { a: number; b: string };
type Bar = { b: number };

const ab: Merge<Foo, Bar> = { a: 1, b: 2 };
```

#### `NumberRange<number, number>`

生成2个数字之间的数字结合,不包括 `TO` 数字限制,只返回相距范围.

```ts
const range: Range<1, 5> = (
  | 1
  | 2
  | 3
  | 4
)
```

#### `ObjectEntries<object>`

将对象转换为数组条目列表。 其类型相当于 `Object.entries()` 方法.

```ts
const entries: ObjectEntries<{
  foo: { a: 1 },
  bar: { a: 2 }
}> = (
  [
    ['foo',  { a: 1 }],
    ['bar',  { a: 2 }],
  ]
)
```

#### `OmitProps<string[], object | object[]>`

用于从字符串列表中排除对象属性,并将返回对象所保留属性. 当通过一个 `Array` 界面将返回值为数组,否则返回值为对象.

```ts

// OBJECT RETURN TYPE
const array: OmitProps<[
  'foo',
  'baz'
], {
  foo: { a: string },
  bar: { a: string },
  baz: { a: string }
}> = {
  bar: { a: 'one' },
}

// ARRAY RETURN TYPE
const array: OmitProps<[
  'foo',
  'baz'
], Array<{
    foo: { a: string },
    bar: { a: string },
    baz: { a: string }
  }>
> = [
  {
    bar: { a: 'one' },
  }
]
```

#### `PartialDeep<object>`

用于从另一个类型创建类型,所有密钥和嵌入密钥设置为可选.

> 被从 [类型庆典](https://github.com/sindresorhus/type-fest/)

```ts
interface IObject {
  deep: {
    a: string;
    b: string;
    c: {
      d: any;
      e: number;
      f: {
        g: string[]
      }
    }
  }
}

// RESULT

const object: PartialDeep<IObject> = {
  deep: {
    a: 'foo'
  }
};

```

#### `PickProps<string[], object | object[]>`

用于从字符串列表中选择对象属性,并将返回对象上选定的属性。 当通过一个 `Array` 界面将返回值为数组,否则返回值为对象.

```ts

// OBJECT RETURN TYPE
const array: PickProps<[
  'foo',
  'baz'
], {
  foo: { a: string },
  bar: { a: string },
  baz: { a: string }
}> = {
  foo: { a: 'one' },
  baz: { a: 'one' },
}

// ARRAY RETURN TYPE
const array: OmitProps<[
  'foo',
  'baz'
], Array<{
    foo: { a: string },
    bar: { a: string },
    baz: { a: string }
  }>
> = [
  {
    foo: { a: 'one' },
    baz: { a: 'one' },
  }
]
```

#### `Split<string, separator>`

代表使用给定字符集或字符集分割字符串的数组。 通常用于返回类型方法,如 `String.prototype.split`。 。 。 .

> 被从 [类型庆典](https://git.io/JX7p5)

```ts
const split: Split<'a,b,c,d', ','> = ['a','b','c','d']
```

#### `Valueof<object>`

对面 `keyof` 返回对象值为联盟类型.

```ts
const values: Valueof<{
  foo: 'a',
  bar: 'b',
  baz: 'c'
}> = (
  | 'a'
  | 'b'
  | 'c'
)
```

### 许可证

许可证根据 [麻省理工学院](https://npmcn.com/package/%40brixtol/tsutils/#readme-LICENCE)

* * *

我们 [♡](https://www.brixtoltextiles.com/discount/4D3V3L0P3RS%5D) 开源!

## 常见问题

### @brixtol/tsutils 是什么？

常用的纺织品类型

### 如何安装 @brixtol/tsutils？

在项目目录运行 npm install @brixtol/tsutils，或使用 pnpm add / yarn add / bun add。

### @brixtol/tsutils 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @brixtol/tsutils 可以商用吗？

@brixtol/tsutils 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @brixtol/tsutils 的下载量有多少？

根据 npm 官方下载统计，@brixtol/tsutils 在 2026/10/09 – 2026/11/07 这 30 天内被下载 9,068 次，日均约 302 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @brixtol/tsutils 还在维护吗？

最新版本 1\.4\.1 发布于 2021/11/14（4 年前）；至今共发布 6 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/11/06。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

