Skip to content

Commit

Permalink
enh: Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Nov 15, 2023
1 parent ced9a0e commit ce26687
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
20 changes: 15 additions & 5 deletions lib/modules/conditions/infrastructure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ type AType = ExtendsCaseMapA[IfMode];
type BType = ExtendsCaseMapB[IfMode];
type CType = ExtendsCaseMapC[IfMode];

interface Explicit<Condition, Then, Else> {
condition: Condition;
then: Then;
else: Else;
}

interface Modes<A, B, C> {
'singleLine': Explicit<A, B, C>;
// @ts-ignore
'natural': Explicit<A, B['then'], B['else']>;
// @ts-ignore
'explicit': Explicit<A['condition'], A['then'], A['else']>;
}

declare global {
/**
* Conditional type that selects one of two possible types based on a boolean condition or a condition object.
Expand Down Expand Up @@ -33,9 +47,5 @@ declare global {
A extends AType,
B extends BType = never,
C extends CType = never
> = ExplicitCondition<{
'singleLine': { condition: A; then: B; else: C };
'natural': { condition: A; then: B['then']; else: B['else'] };
'explicit': A;
}[IfMode]>;
> = ExplicitCondition<Modes<A, B, C>[IfMode]>;
}
4 changes: 2 additions & 2 deletions lib/modules/generals/HKT/domain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ declare global {
* type MyNamedHKT = $<{ x: number; y: string }>;
* // MyNamedHKT is now { args: { x: number; y: string }; return: unknown; x: number; y: string; }
*/
type $<Args extends nLengthTuple = nLengthTuple> = {
type $<Args extends [] | nLengthTuple = []> = {
[$ARGS]: Args;
[x: number]: unknown;
return: unknown;
} & {
[K in Exclude<keyof Args, keyof []>]: Args[K]
[K in Exclude<keyof Args, keyof []>]: Args[K];
};
}
2 changes: 1 addition & 1 deletion lib/modules/generals/HKT/infrastructure.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { $ARGS } from './domain';
import { Call as _Call, Bind as _Bind } from './app';

type $Base = $<nLengthTuple>;
type $Base = $<[] | nLengthTuple>;

/**
* `Call` is a utility type that emulates the behavior of calling a function in JavaScript,
Expand Down
12 changes: 6 additions & 6 deletions lib/modules/numbers/math/infrastructure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import { InternalAdd } from './app/addition';
import { InternalSubstract } from './app/sustraction';

/**
* The `Add` type takes two numeric literal types and produces their sum as a string literal type.
* The `add` type takes two numeric literal types and produces their sum as a number literal type.
* @example
* type Result = Add<5, 10>;
* type Result = add<5, 10>;
* // ^? Result = 15
*
* type Result = Add<2, 3>;
* type Result = add<2, 3>;
* // ^? Result = 5
*/
export type add<A extends number, B extends number> = InternalAdd<A, B>;

/**
* The `Add` type takes two numeric literal types and produces their substraction as a string literal type.
* The `substract` type takes two numeric literal types and produces their substraction as a number literal type.
* @example
* type Result = Add<10, 5>;
* type Result = substract<10, 5>;
* // ^? Result = 5
* type Result = Add<2, 3>;
* type Result = substract<2, 3>;
* // ^? Result = -1
*/
export type substract<A extends number, B extends number> = InternalSubstract<A, B>;
6 changes: 3 additions & 3 deletions lib/modules/promises/infrastructure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { isNever } from '../never/infrastructure';
*
* @example
*
* type A = IsPromise<Promise<number>>;
* type A = isPromise<Promise<number>>;
* // ^? true
* type B = IsPromise<string>;
* type B = isPromise<string>;
* // ^? false
* type C = IsPromise<never>;
* type C = isPromise<never>;
* // ^? false
*/
export type isPromise<T> = If<isNever<T>, {
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/undefined/infrastructure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export type isUndefined<T> = isType<T, undefined>;
/**
* Evaluates if the specified type is `null`.
* @example
* type A = IsNull<null>;
* type A = isNull<null>;
* // ^? true
* type B = IsNull<number>;
* type B = isNull<number>;
* // ^? false
* type C = IsNull<number | null>;
* type C = isNull<number | null>;
* // ^? false
*/
export type isNull<T> = isType<T, null>;
Expand Down

0 comments on commit ce26687

Please sign in to comment.