Skip to content

Commit

Permalink
feat: remove brands and add intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed Apr 29, 2024
1 parent f83f9b0 commit b44fa55
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@ export type Nullish<$Type> = $Type | null | undefined;

export type Either<$Left, $Right> = $Left | $Right;

export type Predicate = (value: unknown) => boolean;

export type Assertion<$Type> = (value: unknown) => asserts value is $Type;

export type UnknownAssertion = Assertion<unknown>;

export type InferAssertion<$Assertion extends Assertion<unknown>> =
$Assertion extends Assertion<infer $Type> ? $Type : never;

export type Class<$Type> = { new (): $Type };

export type UnknownClass = Class<unknown>;

export type Brand<$Name extends string, $Value = None, $Props = None> = {
[$$Name in $Name as `__${$$Name}_brand`]: {
value: $Value;
props: $Props;
};
};

export type AnyBrand = Brand<any, any, any>;

export type Tag<$Name extends string> = {
[$$Name in $Name as `__${$$Name}_brand`]: never;
};

export type AnyTag = Tag<any>;

export type None = Tag<"none">;
export type Intersection<$Values extends unknown[]> = $Values extends [
infer $Head,
...infer $Tail,
]
? $Tail extends [infer _1, ...infer _2]
? $Head & Intersection<$Tail>
: $Head
: never;

0 comments on commit b44fa55

Please sign in to comment.