Skip to content

Commit c2d0caf

Browse files
committed
refactor: consolidate to AssertExtends util
1 parent dd08c2e commit c2d0caf

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/extensions/Throws/Throws.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { type BuilderConfig, createExtension, type Extension, type WithInput } from '../../entrypoints/main.js'
1+
import {
2+
type AssertExtends,
3+
type BuilderConfig,
4+
createExtension,
5+
type Extension,
6+
type WithInput,
7+
} from '../../entrypoints/main.js'
28
import type { ConfigManager } from '../../lib/config-manager/__.js'
39
// todo: no deep imports, rethink these utilities and/or how they are exported from the graffle package.
410
import type { Context } from '../../layers/6_client/context.js'
@@ -34,8 +40,7 @@ type ThrowsExtension = Extension<{
3440

3541
interface Throws_ extends Chain.Extension {
3642
context: Context
37-
// @ts-expect-error untyped params
38-
return: Throws<this['params']>
43+
return: Throws<AssertExtends<this['params'], Chain.Extension.Parameters<Throws_>>>
3944
}
4045

4146
interface Throws<$Args extends Chain.Extension.Parameters<Throws_>> {

src/layers/6_client/extension/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Select } from '../../../documentBuilder/Select/__.js'
22
import type { Anyware } from '../../../lib/anyware/__.js'
33
import type { Chain } from '../../../lib/chain/__.js'
4-
import type { AssertConstraint } from '../../../lib/prelude.js'
4+
import type { AssertExtends } from '../../../lib/prelude.js'
55
import type { TypeFunction } from '../../../lib/type-function/__.js'
66
import type { Fn } from '../../../lib/type-function/TypeFunction.js'
77
import type { RequestPipeline } from '../../../requestPipeline/__.js'
@@ -36,9 +36,9 @@ export interface TypeHooks {
3636
export type RunTypeHookOnRequestResult<
3737
$Context extends Context,
3838
$Params extends Extension.Hooks.OnRequestResult.Params,
39-
> = AssertConstraint<
40-
Extension.Hooks.OnRequestResult.Params,
41-
TypeFunction.CallPipeline<$Context['config']['typeHooks']['onRequestResult'], $Params>
39+
> = AssertExtends<
40+
TypeFunction.CallPipeline<$Context['config']['typeHooks']['onRequestResult'], $Params>,
41+
Extension.Hooks.OnRequestResult.Params
4242
>
4343

4444
export interface EmptyTypeHooks {

src/lib/chain/Definition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Simplify } from 'type-fest'
2-
import type { ForceExtends, mergeArrayOfObjects } from '../prelude.js'
2+
import type { AssertExtends, mergeArrayOfObjects } from '../prelude.js'
33
import type { TypeFunction } from '../type-function/__.js'
44
import type { Context, Extension } from './Extension.js'
55

@@ -9,7 +9,7 @@ import type { Context, Extension } from './Extension.js'
99
*/
1010
export interface ChainDefinition_<$Extensions extends [...Extension[]] = [...Extension[]]> extends TypeFunction.Fn {
1111
extensions: $Extensions
12-
return: ChainDefinition_<ForceExtends<this['params'], Extension[]>>
12+
return: ChainDefinition_<AssertExtends<this['params'], Extension[]>>
1313
}
1414

1515
type CallChainDefinition<_ extends ChainDefinition_, $Arguments extends [...Extension[]]> = TypeFunction.Call<

src/lib/prelude.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ export type GetOrNever<$O extends object, $P extends string> =
600600
: never
601601

602602
// dprint-ignore
603-
export type AssertConstraint<$Constraint, $Type> =
603+
export type AssertExtends<$Type, $Constraint> =
604604
$Type extends $Constraint
605605
? $Type
606606
: never
@@ -636,5 +636,3 @@ export type SimplifyExcept<$ExcludeType, $Type> =
636636
: $Type extends $ExcludeType
637637
? $Type
638638
: {[TypeKey in keyof $Type]: $Type[TypeKey]}
639-
640-
export type ForceExtends<T, U> = T extends U ? T : U

0 commit comments

Comments
 (0)