Skip to content

Commit

Permalink
Make constructors return full sum-type not specific instance
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Feb 27, 2024
1 parent e6378f0 commit d4a759f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Definition = Record<string, (v: any) => any>
export type Constructors<N extends string, D extends Definition> = {
export type InternalConstructors<N extends string, D extends Definition> = {
[R in keyof D]: {
(value: Parameters<D[R]>[0]): {
type: N
Expand All @@ -8,6 +8,11 @@ export type Constructors<N extends string, D extends Definition> = {
}
}
}
export type Constructors<N extends string, D extends Definition> = {
[R in keyof D]: {
(value: Parameters<D[R]>[0]): InternalInstance<N, D, keyof D>
}
}
export type MatchOptions<D extends Definition, T> = {
[R in keyof D]: {
(value: Parameters<D[R]>[0]): T
Expand Down Expand Up @@ -97,7 +102,7 @@ type InternalInstance<
N extends string,
D extends Definition,
K extends keyof D,
> = ReturnType<Constructors<N, D>[K]>
> = ReturnType<InternalConstructors<N, D>[K]>

function match(instance: any, options: any): any {
return options[instance.tag](instance.value)
Expand Down

0 comments on commit d4a759f

Please sign in to comment.