diff --git a/.changeset/flat-dodos-fry.md b/.changeset/flat-dodos-fry.md new file mode 100644 index 0000000..52fe552 --- /dev/null +++ b/.changeset/flat-dodos-fry.md @@ -0,0 +1,5 @@ +--- +"@effect-rx/rx": patch +--- + +cast undefined to void for .fn arguments diff --git a/docs/rx/Rx.ts.md b/docs/rx/Rx.ts.md index 5f86ea3..670d11f 100644 --- a/docs/rx/Rx.ts.md +++ b/docs/rx/Rx.ts.md @@ -70,6 +70,9 @@ Added in v1.0.0 - [TypeId (type alias)](#typeid-type-alias) - [WritableTypeId](#writabletypeid) - [WritableTypeId (type alias)](#writabletypeid-type-alias) +- [utils](#utils) + - [RxResultFn (namespace)](#rxresultfn-namespace) + - [ArgToVoid (type alias)](#argtovoid-type-alias) --- @@ -243,11 +246,11 @@ export declare const fn: { ( fn: Rx.ReadFn>, options?: { readonly initialValue?: A | undefined } | undefined - ): RxResultFn extends true ? void : Arg, A, E> + ): RxResultFn, A, E> ( fn: Rx.ReadFn>, options?: { readonly initialValue?: A | undefined } | undefined - ): RxResultFn extends true ? void : Arg, A, E | NoSuchElementException> + ): RxResultFn, A, E | NoSuchElementException> } ``` @@ -259,8 +262,8 @@ Added in v1.0.0 ```ts export declare const fnSync: { - (f: Rx.ReadFn): Writable, Arg> - (f: Rx.ReadFn, options: { readonly initialValue: A }): Writable + (f: Rx.ReadFn): Writable, RxResultFn.ArgToVoid> + (f: Rx.ReadFn, options: { readonly initialValue: A }): Writable> } ``` @@ -661,13 +664,13 @@ export interface RxRuntime extends Rx, E options?: { readonly initialValue?: A } - ): RxResultFn extends true ? void : Arg, A, E | ER> + ): RxResultFn, A, E | ER> ( fn: Rx.ReadFn>, options?: { readonly initialValue?: A } - ): RxResultFn extends true ? void : Arg, A, E | ER | NoSuchElementException> + ): RxResultFn, A, E | ER | NoSuchElementException> } readonly pull: ( @@ -796,3 +799,19 @@ export type WritableTypeId = typeof WritableTypeId ``` Added in v1.0.0 + +# utils + +## RxResultFn (namespace) + +Added in v1.0.0 + +### ArgToVoid (type alias) + +**Signature** + +```ts +export type ArgToVoid = Arg extends infer A ? (unknown extends A ? void : A extends undefined ? void : A) : never +``` + +Added in v1.0.0 diff --git a/packages/rx/src/Rx.ts b/packages/rx/src/Rx.ts index 29a7bf0..f771545 100644 --- a/packages/rx/src/Rx.ts +++ b/packages/rx/src/Rx.ts @@ -19,7 +19,6 @@ import * as Runtime from "effect/Runtime" import * as Scope from "effect/Scope" import * as Stream from "effect/Stream" import * as SubscriptionRef from "effect/SubscriptionRef" -import type * as Types from "effect/Types" import * as internalRegistry from "./internal/registry.js" import { runCallbackSync } from "./internal/runtime.js" import * as Result from "./Result.js" @@ -521,10 +520,10 @@ export interface RxRuntime extends Rx, E readonly fn: { (fn: Rx.ReadFn>, options?: { readonly initialValue?: A - }): RxResultFn extends true ? void : Arg, A, E | ER> + }): RxResultFn, A, E | ER> (fn: Rx.ReadFn>, options?: { readonly initialValue?: A - }): RxResultFn extends true ? void : Arg, A, E | ER | NoSuchElementException> + }): RxResultFn, A, E | ER | NoSuchElementException> } readonly pull: (create: Rx.Read> | Stream.Stream, options?: { @@ -711,14 +710,14 @@ export const subRef: { export const fnSync: { ( f: Rx.ReadFn - ): Writable, Arg> + ): Writable, RxResultFn.ArgToVoid> ( f: Rx.ReadFn, options: { readonly initialValue: A } - ): Writable + ): Writable> } = (f: Rx.ReadFn, options?: { readonly initialValue?: A -}): Writable | A, Arg> => { +}): Writable | A, RxResultFn.ArgToVoid> => { const argRx = state<[number, Arg]>([0, undefined as any]) const hasInitialValue = options?.initialValue !== undefined return writable(function(get) { @@ -728,7 +727,7 @@ export const fnSync: { } return hasInitialValue ? f(arg, get) : Option.some(f(arg, get)) }, function(ctx, arg) { - ctx.set(argRx, [ctx.get(argRx)[0] + 1, arg]) + ctx.set(argRx, [ctx.get(argRx)[0] + 1, arg as Arg]) }) } @@ -738,6 +737,16 @@ export const fnSync: { */ export interface RxResultFn extends Writable, Arg | Reset> {} +/** + * @since 1.0.0 + */ +export declare namespace RxResultFn { + /** + * @since 1.0.0 + */ + export type ArgToVoid = Arg extends infer A ? unknown extends A ? void : A extends undefined ? void : A : never +} + /** * @since 1.0.0 * @category symbols @@ -757,13 +766,13 @@ export type Reset = typeof Reset export const fn: { (fn: Rx.ReadFn>, options?: { readonly initialValue?: A - }): RxResultFn extends true ? void : Arg, A, E> + }): RxResultFn, A, E> (fn: Rx.ReadFn>, options?: { readonly initialValue?: A - }): RxResultFn extends true ? void : Arg, A, E | NoSuchElementException> + }): RxResultFn, A, E | NoSuchElementException> } = (f: Rx.ReadFn | Effect.Effect>, options?: { readonly initialValue?: A -}): RxResultFn extends true ? void : Arg, A, E | NoSuchElementException> => { +}): RxResultFn, A, E | NoSuchElementException> => { const [read, write] = makeResultFn(f, options) return writable(read, write) as any }