Skip to content

Commit

Permalink
Prevent recursive Result types
Browse files Browse the repository at this point in the history
  • Loading branch information
greguz committed Jan 23, 2024
1 parent aeca382 commit f7bb5d4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions result.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ declare function is(value: unknown): value is IResult<unknown, unknown>
/**
* https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
*/
export type Ok<T> = [T] extends IResult<infer O, infer E>
export type Ok<T> = [T] extends [IResult<infer O, infer E>]
? IResult<O, E>
: IResult<T, never>

Expand All @@ -85,7 +85,7 @@ declare function ok<T = undefined>(value?: T): Ok<T>
/**
* https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
*/
export type Err<T> = [T] extends IResult<infer O, infer E>
export type Err<T> = [T] extends [IResult<infer O, infer E>]
? IResult<O, E>
: IResult<never, T>

Expand Down

0 comments on commit f7bb5d4

Please sign in to comment.