From c2d0caf3f780f22f2e597fe642f193e9dac81afd Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 30 Oct 2024 20:21:02 -0400 Subject: [PATCH] refactor: consolidate to AssertExtends util --- src/extensions/Throws/Throws.ts | 11 ++++++++--- src/layers/6_client/extension/extension.ts | 8 ++++---- src/lib/chain/Definition.ts | 4 ++-- src/lib/prelude.ts | 4 +--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/extensions/Throws/Throws.ts b/src/extensions/Throws/Throws.ts index 93075c95c..700fa5f43 100644 --- a/src/extensions/Throws/Throws.ts +++ b/src/extensions/Throws/Throws.ts @@ -1,4 +1,10 @@ -import { type BuilderConfig, createExtension, type Extension, type WithInput } from '../../entrypoints/main.js' +import { + type AssertExtends, + type BuilderConfig, + createExtension, + type Extension, + type WithInput, +} from '../../entrypoints/main.js' import type { ConfigManager } from '../../lib/config-manager/__.js' // todo: no deep imports, rethink these utilities and/or how they are exported from the graffle package. import type { Context } from '../../layers/6_client/context.js' @@ -34,8 +40,7 @@ type ThrowsExtension = Extension<{ interface Throws_ extends Chain.Extension { context: Context - // @ts-expect-error untyped params - return: Throws + return: Throws>> } interface Throws<$Args extends Chain.Extension.Parameters> { diff --git a/src/layers/6_client/extension/extension.ts b/src/layers/6_client/extension/extension.ts index 569395609..beac76669 100644 --- a/src/layers/6_client/extension/extension.ts +++ b/src/layers/6_client/extension/extension.ts @@ -1,7 +1,7 @@ import type { Select } from '../../../documentBuilder/Select/__.js' import type { Anyware } from '../../../lib/anyware/__.js' import type { Chain } from '../../../lib/chain/__.js' -import type { AssertConstraint } from '../../../lib/prelude.js' +import type { AssertExtends } from '../../../lib/prelude.js' import type { TypeFunction } from '../../../lib/type-function/__.js' import type { Fn } from '../../../lib/type-function/TypeFunction.js' import type { RequestPipeline } from '../../../requestPipeline/__.js' @@ -36,9 +36,9 @@ export interface TypeHooks { export type RunTypeHookOnRequestResult< $Context extends Context, $Params extends Extension.Hooks.OnRequestResult.Params, -> = AssertConstraint< - Extension.Hooks.OnRequestResult.Params, - TypeFunction.CallPipeline<$Context['config']['typeHooks']['onRequestResult'], $Params> +> = AssertExtends< + TypeFunction.CallPipeline<$Context['config']['typeHooks']['onRequestResult'], $Params>, + Extension.Hooks.OnRequestResult.Params > export interface EmptyTypeHooks { diff --git a/src/lib/chain/Definition.ts b/src/lib/chain/Definition.ts index bbfd46c93..555ffa4b8 100644 --- a/src/lib/chain/Definition.ts +++ b/src/lib/chain/Definition.ts @@ -1,5 +1,5 @@ import type { Simplify } from 'type-fest' -import type { ForceExtends, mergeArrayOfObjects } from '../prelude.js' +import type { AssertExtends, mergeArrayOfObjects } from '../prelude.js' import type { TypeFunction } from '../type-function/__.js' import type { Context, Extension } from './Extension.js' @@ -9,7 +9,7 @@ import type { Context, Extension } from './Extension.js' */ export interface ChainDefinition_<$Extensions extends [...Extension[]] = [...Extension[]]> extends TypeFunction.Fn { extensions: $Extensions - return: ChainDefinition_> + return: ChainDefinition_> } type CallChainDefinition<_ extends ChainDefinition_, $Arguments extends [...Extension[]]> = TypeFunction.Call< diff --git a/src/lib/prelude.ts b/src/lib/prelude.ts index 7f0509067..ba3ce1908 100644 --- a/src/lib/prelude.ts +++ b/src/lib/prelude.ts @@ -600,7 +600,7 @@ export type GetOrNever<$O extends object, $P extends string> = : never // dprint-ignore -export type AssertConstraint<$Constraint, $Type> = +export type AssertExtends<$Type, $Constraint> = $Type extends $Constraint ? $Type : never @@ -636,5 +636,3 @@ export type SimplifyExcept<$ExcludeType, $Type> = : $Type extends $ExcludeType ? $Type : {[TypeKey in keyof $Type]: $Type[TypeKey]} - -export type ForceExtends = T extends U ? T : U