@fringeworks/types

中文文档
1.2.0发布于 2026/11/12MITTypeScriptESM + CJS零依赖近 30 天下载 2517

A library some will find handy, offering TypeScript utility types and constants that enumerate the values of a type.

原始使用文档
文档目录17 节
  1. Installation
  2. Types and Constants
  3. Value types
  4. Constants
  5. Record types
  6. Dictionary types
  7. Array types
  8. Synchronous function types
  9. Asynchronous function types
  10. Iteratee types
  11. Color types
  12. Advanced utility types
  13. Keys<RECORD, TYPE>
  14. Prefixed<PREFIX, RECORD, KEYS>
  15. PrefixedUnion<PREFIX, UNION, MEMBERS>
  16. Override<BASE, OVERRIDES>
  17. License

@fringeworks/types

@fringeworks/types is a library some will find handy, offering TypeScript utility types and constants that enumerate the values of a type.

日本語のREADMEはこちら

Installation

npm install @fringeworks/types

Types and Constants

Value types

TypeDefinitionDescription
Nullishundefined | nullnull or undefined
PrimitiveNullish | boolean | number | bigint | string | symbolPrimitive values
EmptyNullish | ''Nullish plus empty string
FalsyEmpty | false | 0 | 0nJavaScript falsy values (excluding NaN)

Falsy does not include NaN, because NaN has no literal type and could only be expressed by including all of number. -0 is the same as 0 at the type level.

Constants

Constants that enumerate the possible values of a type. A type with the same name is also exported, so each can be used both as a value and as a type.

ConstantDescription
ToStringResultResults of Object.prototype.toString.call(value) for the major built-in objects
TypeOfResultResults of typeof
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;
}

Record types

Generic record types whose keys are PropertyKey (string | number | symbol). To specify the value type, use Record<PropertyKey, VALUE> directly.

TypeDefinitionDescription
LooseRecordRecord<PropertyKey, any>Flexibility-first type that accepts any value type
StrictRecordRecord<PropertyKey, unknown>Safety-first type that requires a type guard to use

Dictionary types

Record types whose keys are string only. To specify the value type, use Record<string, VALUE> directly.

TypeDefinitionDescription
LooseDictionaryRecord<string, any>Flexibility-first type that accepts any value type
StrictDictionaryRecord<string, unknown>Safety-first type that requires a type guard to use

Array types

TypeDefinitionDescription
LooseArrayany[]Flexibility-first array type that accepts any element
StrictArrayunknown[]Safety-first array type that requires a type guard to use

Synchronous function types

TypeDescription
SyncFunction<PARAMS, RESULT>Base type with configurable parameter type PARAMS (a tuple, default never[]) and return type RESULT (default unknown)
LooseSyncFunctionFlexibility-first type with any parameters and return value
StrictSyncFunctionSafety-first type with never[] parameters and unknown return value. Same as SyncFunction with the defaults

Asynchronous function types

TypeDescription
AsyncFunction<PARAMS, RESULT>Base type with configurable parameter type PARAMS (a tuple, default never[]) and return Promise<RESULT> (RESULT defaults to unknown)
LooseAsyncFunctionFlexibility-first type with any parameters and return value
StrictAsyncFunctionSafety-first type with never[] parameters and Promise<unknown> return value. Same as AsyncFunction with the defaults

Iteratee types

TypeSignatureDescription
IndexedIteratee<VALUE, RESULT>(value: VALUE, index: number, data: readonly VALUE[]) => RESULTCallback for iterating over arrays
FilterFunction<VALUE>(value: VALUE) => booleanFunction that tells whether an element matches a condition. Can be passed to Array.prototype.filter
SortFunction<VALUE>(a: VALUE, b: VALUE) => numberComparison function that returns the order of two elements (negative to put a first). Can be passed to Array.prototype.sort

Color types

TypeDefinitionDescription
AbsoluteColorHexColor | FunctionalColor | NamedColorA concrete color value: hex colors, color functions, or color names
HexColor`#${string}`A hex color
FunctionalColor`rgb(${string})` | … | `color(${string})`A color written with a color function
NamedColor'aliceblue' | … | 'yellowgreen' | 'transparent'CSS color names (the 148 names and transparent)

AbsoluteColor is for code that computes colors in JavaScript. Values that are not decided until rendering, such as CSS variables (var()), currentColor, and inherit, are type errors. FunctionalColor accepts the color functions rgb(), rgba(), hsl(), hsla(), hwb(), lab(), lch(), oklab(), oklch(), and color() (not color-mix() and the like).

The type checks only the syntax, not the content (such as '#zzz'). Color names and function names are accepted in lowercase only.

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

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

Advanced utility types

Keys<RECORD, TYPE>

Generates a union type of the keys of a record. When TYPE is specified, only keys whose values extend that type are included.
Optional properties are checked by their value type without the undefined added by ?.

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>

Generates a new type by prepending a camelCase prefix to the specified properties of a record.
When KEYS is omitted, all properties are targeted. Numeric and symbol keys are kept as they are, without a prefix.

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>

Generates a new union type by prepending a camelCase prefix to the members of a union.
When MEMBERS is omitted, all members are targeted. Non-string members are kept as they are, without a prefix.

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>

Generates a type in which the properties of BASE are overridden by those of OVERRIDES. Properties with the same name take their type from OVERRIDES.

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 }

License

MIT

版本与发布记录

@fringeworks/types 共发布 9 个版本,首次发布于 2026/10/04;过去 12 个月发布了 9 个版本。

版本发布日期距今
1.2.0latest2026/11/123 天前
1.1.12026/11/078 天前
1.1.02026/11/078 天前
1.0.02026/10/2521 天前
0.9.22026/10/2224 天前
0.9.12026/10/1630 天前

关于 @fringeworks/types 的常见问题

@fringeworks/types 是什么?

A library some will find handy, offering TypeScript utility types and constants that enumerate the values of a type.

如何安装 @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 和提交记录判断。