Skip to content

Commit

Permalink
refactor: consolidate to AssertExtends util
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Oct 31, 2024
1 parent dd08c2e commit c2d0caf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/extensions/Throws/Throws.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -34,8 +40,7 @@ type ThrowsExtension = Extension<{

interface Throws_ extends Chain.Extension {
context: Context
// @ts-expect-error untyped params
return: Throws<this['params']>
return: Throws<AssertExtends<this['params'], Chain.Extension.Parameters<Throws_>>>
}

interface Throws<$Args extends Chain.Extension.Parameters<Throws_>> {
Expand Down
8 changes: 4 additions & 4 deletions src/layers/6_client/extension/extension.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/chain/Definition.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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_<ForceExtends<this['params'], Extension[]>>
return: ChainDefinition_<AssertExtends<this['params'], Extension[]>>
}

type CallChainDefinition<_ extends ChainDefinition_, $Arguments extends [...Extension[]]> = TypeFunction.Call<
Expand Down
4 changes: 1 addition & 3 deletions src/lib/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -636,5 +636,3 @@ export type SimplifyExcept<$ExcludeType, $Type> =
: $Type extends $ExcludeType
? $Type
: {[TypeKey in keyof $Type]: $Type[TypeKey]}

export type ForceExtends<T, U> = T extends U ? T : U

0 comments on commit c2d0caf

Please sign in to comment.