Minor refactors

This commit is contained in:
2025-03-28 22:06:09 +01:00
parent 0c903e1087
commit 709165bab0
10 changed files with 20 additions and 54 deletions

View File

@@ -1,35 +0,0 @@
import * as Function from "./Function";
import * as Types from "./Types";
declare const BrandTypeId: unique symbol;
export type BrandTypeId = typeof BrandTypeId;
declare const ConstructorTypeId: unique symbol;
export type ConstructorTypeId = typeof ConstructorTypeId;
export interface Brand<in out K extends string | symbol> {
readonly [BrandTypeId]: {
readonly [k in K]: K;
};
}
export declare namespace Brand {
export interface Constructor<in out A extends Brand<any>> {
readonly [ConstructorTypeId]: ConstructorTypeId;
(args: Brand.Unbranded<A>): A;
}
export type Unbranded<P> = P extends infer Q & Brands<P> ? Q : P;
export type Brands<P> = P extends Brand<any>
? Types.UnionToIntersection<{
[k in keyof P[BrandTypeId]]: k extends string | symbol ? Brand<k> : never
}[keyof P[BrandTypeId]]>
: never;
}
export type Branded<A, K extends string | symbol> = A & Brand<K>;
export const nominal = <A extends Brand<any>>(): Brand.Constructor<A> => {
return Function.identity as Brand.Constructor<A>;
};

View File

@@ -1,4 +0,0 @@
export const identity = <A>(a: A): A => a;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- unsafe by design
export const unsafeCoerce: <A, B>(a: A) => B = identity as any;

View File

@@ -1 +0,0 @@
export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;

View File

@@ -1,4 +1,4 @@
import * as Brand from "./Brand";
import { Brand } from "effect";
export type UUID = Brand.Branded<string, "UUID">;
export const UUID = Brand.nominal<UUID>();