# @fringeworks/types 中文文档

规范地址：https://npmcn.com/package/%40fringeworks/types/

版本：1\.2\.0
npm 元数据更新时间：2026-11-12T12:08:57.054Z
中文译文更新时间：2026-11-15T14:38:35.129Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40fringeworks/types
原文对照：https://npmcn.com/package/%40fringeworks/types/?lang=original
项目主页：https://github.com/fringeworks-js/types#readme
源码仓库：https://github.com/fringeworks-js/types

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

- 包体积（解压后）：54.9 kB，30 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2026-10-04T13:46:54.596Z
- 最新版本发布：2026-11-12T12:08:56.674Z
- 近 30 天下载量：2517（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：9（近 12 个月 9 个）

## 中文简介

库中有些会发现手动, 提供 TypeScript 工具类型和常数, 列出一个类型的值 .

## 安装

```sh
npm install @fringeworks/types
```

也可以使用：`pnpm add @fringeworks/types`、`yarn add @fringeworks/types`、`bun add @fringeworks/types`

## README

# @ fringeworks/ 类型

`@fringeworks/types` 是一个库, 某些将找到方便, 提供 TypeScript 工具类型和常数, 以列出一个类型的值 .

**[\[ README \]](https://npmcn.com/package/%40fringeworks/types/README.ja.md)**

## 安装

```sh
npm install @fringeworks/types
```

## 类型和常数

### 数值类型

| 类型 | 定义 | 说明 |
| --- | --- | --- |
| `Nullish` | `undefined | null` | 无效或未定义 |
| `Primitive` | `Nullish | boolean | number | bigint | string | symbol` | 原始价值 |
| `Empty` | `Nullish | ''` | 无效加空字符串 |
| `Falsy` | `Empty | false | 0 | 0n` | JavaScript falsy 值( 不包括) `NaN`(中文(简体) ) |

`Falsy` 不包含 `NaN`,因为 `NaN` 没有字面类型,只能通过包括所有 `number`。 。 。 . `-0` 与 `0` 在类型级别.

### 常数

列出某一类型可能值的常数。 也导出同名类型,因此每个类型都可以作为值和类型.

| 常数 | 说明 |
| --- | --- |
| `ToStringResult` | 结果 `Object.prototype.toString.call(value)` 主要内置对象 |
| `TypeOfResult` | 结果 `typeof` |

```ts
import { ToStringResult, TypeOfResult } from '@fringeworks/types';

// Use as a value
Object.prototype.toString.call([]) === ToStringResult.Array; // => true

// Use as a type
function getType(value: unknown): TypeOfResult {
  return typeof value;
}
```

### 记录类型

键为 `PropertyKey` (单位:千美元)`string | number | symbol`) (中文(简体) ). 指定值类型, 使用 `Record<PropertyKey, VALUE>` 直接说.

| 类型 | 定义 | 说明 |
| --- | --- | --- |
| `LooseRecord` | `Record<PropertyKey, any>` | 接受任何值类型的灵活性第一类型 |
| `StrictRecord` | `Record<PropertyKey, unknown>` | 需要类型守护的安全第一类型 |

### 词典类型

键为 `string` 只有这个 指定值类型, 使用 `Record<string, VALUE>` 直接说.

| 类型 | 定义 | 说明 |
| --- | --- | --- |
| `LooseDictionary` | `Record<string, any>` | 接受任何值类型的灵活性第一类型 |
| `StrictDictionary` | `Record<string, unknown>` | 需要类型守护的安全第一类型 |

### 阵列类型

| 类型 | 定义 | 说明 |
| --- | --- | --- |
| `LooseArray` | `any[]` | 接受任何元素的弹性第一阵列类型 |
| `StrictArray` | `unknown[]` | 需要使用类型守护的安全第一阵列类型 |

### 同步函数类型

| 类型 | 说明 |
| --- | --- |
| `SyncFunction<PARAMS, RESULT>` | 有可配置参数类型的基准类型 `PARAMS` (tuple,默认) `never[]`返回类型 `RESULT` (默认) `unknown`(中文(简体) ) |
| `LooseSyncFunction` | 灵活性第一类型 `any` 参数和返回值 |
| `StrictSyncFunction` | 安全第一类型 `never[]` 参数和 `unknown` 返回值。 与 `SyncFunction` 默认值 |

### 同步函数类型

| 类型 | 说明 |
| --- | --- |
| `AsyncFunction<PARAMS, RESULT>` | 有可配置参数类型的基准类型 `PARAMS` (tuple,默认) `never[]`返回时 `Promise<RESULT>` (单位:千美元)`RESULT` 默认为 `unknown`(中文(简体) ) |
| `LooseAsyncFunction` | 灵活性第一类型 `any` 参数和返回值 |
| `StrictAsyncFunction` | 安全第一类型 `never[]` 参数和 `Promise<unknown>` 返回值。 与 `AsyncFunction` 默认值 |

### 斜纹类型

| 类型 | 签署 | 说明 |
| --- | --- | --- |
| `IndexedIteratee<VALUE, RESULT>` | `(value: VALUE, index: number, data: readonly VALUE[]) => RESULT` | 回呼在阵列上延展 |
| `FilterFunction<VALUE>` | `(value: VALUE) => boolean` | 显示元素是否匹配条件的函数 。 可以传到 `Array.prototype.filter` |
| `SortFunction<VALUE>` | `(a: VALUE, b: VALUE) => number` | 比较函数返回两个元素的顺序(负置出) `a` (第一编) 可以传到 `Array.prototype.sort` |

### 颜色类型

| 类型 | 定义 | 说明 |
| --- | --- | --- |
| `AbsoluteColor` | `HexColor | FunctionalColor | NamedColor` | 混凝土颜色值:十六进制颜色、颜色函数或颜色名称 |
| `HexColor` | `` `#${string}` `` | 十六进制颜色 |
| `FunctionalColor` | `` `rgb(${string})` `` | | `` `color(${string})` `` | 带有色彩功能的颜色 |
| `NamedColor` | `'aliceblue'` | | `'yellowgreen'` | `'transparent'` | CSS 颜色名称(148个名称和 `transparent`(中文(简体) ) |

`AbsoluteColor` 用于在 JavaScript 中计算颜色的代码。 在渲染之前尚未决定的值,例如 CSS 变量(`var()`, (中文(简体) ), `currentColor`,以及 `inherit`,是类型错误. `FunctionalColor` 接受颜色函数 `rgb()`, (中文(简体) ), `rgba()`, (中文(简体) ), `hsl()`, (中文(简体) ), `hsla()`, (中文(简体) ), `hwb()`, (中文(简体) ), `lab()`, (中文(简体) ), `lch()`, (中文(简体) ), `oklab()`, (中文(简体) ), `oklch()`,以及 `color()` (无) `color-mix()` 和类似.

类型只检查语法,而不是内容(例如 `'#zzz'`) (中文(简体) ). 颜色名称和函数名称只在小写中被接受.

```ts
import type { AbsoluteColor } from '@fringeworks/types';

const accent: AbsoluteColor = '#2f6fde'; // OK
const brand: AbsoluteColor = 'var(--brand)'; // Type error
```

## 高级公用事业类型

### `Keys<RECORD, TYPE>`

生成记录键的结合类型。 何时 `TYPE` ,只包含其值延伸该类型的密钥.  
可选属性按其值类型检查,而不包含 `undefined` 由 `?`。 。 。 .

```ts
import type { Keys } from '@fringeworks/types';

type Props = {
  id: number;
  name: string;
  label: string;
  createdAt: Date;
  note?: string;
};

// Union of all keys
type AllKeys = Keys<Props>;
// => 'id' | 'name' | 'label' | 'createdAt' | 'note'

// Only keys whose value is string
type StringKeys = Keys<Props, string>;
// => 'name' | 'label' | 'note'
```

### `Prefixed<PREFIX, RECORD, KEYS>`

通过在记录的指定属性上预置骆驼Case前缀来生成新类型.  
何时 `KEYS` ,所有属性都成为目标。 数字和符号键按原样保存,没有前缀.

```ts
import type { Prefixed } from '@fringeworks/types';

type Props = {
  width: number;
  height: number;
  color: string;
};

// Prefix all properties
type PrefixedProps = Prefixed<'default', Props>;
// => { defaultWidth: number; defaultHeight: number; defaultColor: string }

// Prefix only selected properties
type PartialPrefixedProps = Prefixed<'default', Props, 'width' | 'height'>;
// => { defaultWidth: number; defaultHeight: number; color: string }
```

### `PrefixedUnion<PREFIX, UNION, MEMBERS>`

使用骆驼来创造新的工会类型 工会成员的案件前缀.  
何时 `MEMBERS` 所有成员都成为目标。 非弦成员保持原样,没有前缀.

```ts
import type { PrefixedUnion } from '@fringeworks/types';

type Direction = 'top' | 'right' | 'bottom' | 'left';

// Prefix all members
type PaddingKeys = PrefixedUnion<'padding', Direction>;
// => 'paddingTop' | 'paddingRight' | 'paddingBottom' | 'paddingLeft'

// Prefix only selected members
type PartialMarginKeys = PrefixedUnion<'margin', Direction, 'top' | 'bottom'>;
// => 'marginTop' | 'right' | 'marginBottom' | 'left'
```

### `Override<BASE, OVERRIDES>`

生成属性为 `BASE` 被弃绝者 `OVERRIDES`。同名属性从 `OVERRIDES`。 。 。 .

```ts
import type { Override } from '@fringeworks/types';

type Base = { id: number; name: string };

type Props = Override<Base, { id: string; label: string }>;
// => { name: string } & { id: string; label: string }
```

## 许可证

麻省理工学院

## 常见问题

### @fringeworks/types 是什么？

库中有些会发现手动, 提供 TypeScript 工具类型和常数, 列出一个类型的值 \.

### 如何安装 @fringeworks/types？

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

### @fringeworks/types 支持 TypeScript 吗？

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

### @fringeworks/types 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @fringeworks/types 可以商用吗？

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

### @fringeworks/types 的下载量有多少？

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

### @fringeworks/types 还在维护吗？

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

