diff --git a/lib/index.ts b/lib/index.ts index d76344c..7096846 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -151,7 +151,7 @@ export function type( export type Value = A extends API ? Instance['value'] - : A extends { type: string, tag: string, value: any } + : A extends { type: string; tag: string; value: any } ? A['value'] : A extends (x: any) => any ? Parameters[0] @@ -209,33 +209,28 @@ export type UseGet = { visitor: (value: InternalValue) => T, ) => T } - export type UseGetDefault = { [Key in keyof D as GetTemplate]: ( value: InternalInstance, fallback: T, - ) => T | InternalInstance['value'] + ) => T | InternalInstance['value'] } - export type UseGetNull = { [Key in keyof D as GetTemplate]: ( value: InternalInstance, - ) => null | InternalInstance['value'] + ) => null | InternalInstance['value'] } + type InternalValue any> = Parameters[0] -export type Instance = +export type Instance = A extends CoreAPI - ? InternalInstance< - A['type'], - A['definition'], - keyof A['definition'] - > - // constructor - : A extends (x:any) => { value: any } - ? ReturnType - : never + ? InternalInstance + : // constructor + A extends (x: any) => { value: any } + ? ReturnType + : never export function either( name: Name, @@ -269,12 +264,11 @@ export function either( return api as EitherApi } - export function maybe( name: Name, - yes: (_: Yes) => any + yes: (_: Yes) => any, ) { - return either(name, yes) as any as EitherApi> + return either(name, yes) as any as EitherApi> } export function Resource(name: Name) {