Skip to content

Commit

Permalink
Remove UnknownIfNever
Browse files Browse the repository at this point in the history
  • Loading branch information
decs committed Oct 14, 2024
1 parent a5c728d commit c732153
Show file tree
Hide file tree
Showing 48 changed files with 141 additions and 346 deletions.
15 changes: 3 additions & 12 deletions packages/all/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions packages/arktype/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/arktype/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export interface AdapterResolver extends Resolver {
base: IfDefined<Type, 'arktype'>;
input: this['schema'] extends this['base']
? this['schema']['inferIn']
: never;
output: this['schema'] extends this['base'] ? this['schema']['infer'] : never;
: unknown;
output: this['schema'] extends this['base']
? this['schema']['infer']
: unknown;
}
15 changes: 3 additions & 12 deletions packages/class-validator/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/class-validator/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export interface AdapterResolver extends Resolver {
input: this['schema'] extends this['base']
? this['schema'] extends {prototype: unknown}
? Attributes<this['schema']['prototype']>
: never
: never;
: unknown
: unknown;
output: this['schema'] extends this['base']
? this['schema'] extends {prototype: unknown}
? Attributes<this['schema']['prototype']>
: never
: never;
: unknown
: unknown;
}
8 changes: 1 addition & 7 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ export {
SerializationAdapter,
ToJSONSchema,
} from './serialization';
export {
IfDefined,
memoize,
memoizeWithKey,
UnknownIfNever,
unsupportedAdapter,
} from './utils';
export {IfDefined, memoize, memoizeWithKey, unsupportedAdapter} from './utils';
export {
Assert,
createAssert,
Expand Down
20 changes: 7 additions & 13 deletions packages/core/src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import type {IfDefined} from './utils';

export interface Resolver<TSchema = unknown> {
schema: TSchema;
input: unknown;
output: unknown;
base: unknown;
}

export type SchemaFrom<TResolver extends Resolver> = IfDefined<
TResolver['base']
>;
export type SchemaFrom<TResolver extends Resolver> = TResolver['base'];

export type InputFrom<TResolver extends Resolver, TSchema> =
TSchema extends SchemaFrom<TResolver>
? IfDefined<(TResolver & {schema: TSchema})['input']>
: never;
export type InputFrom<TResolver extends Resolver, TSchema> = (TResolver & {
schema: TSchema;
})['input'];

export type OutputFrom<TResolver extends Resolver, TSchema> =
TSchema extends SchemaFrom<TResolver>
? IfDefined<(TResolver & {schema: TSchema})['output']>
: never;
export type OutputFrom<TResolver extends Resolver, TSchema> = (TResolver & {
schema: TSchema;
})['output'];
7 changes: 4 additions & 3 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type {Resolver, SchemaFrom} from './resolver';

export type IfDefined<TValue, TModule extends string = ''> = unknown extends TValue
export type IfDefined<
TValue,
TModule extends string = '',
> = unknown extends TValue
? TModule extends ''
? never
: `Cannot find module '${TModule}'`
: TValue;

export type UnknownIfNever<T> = [T] extends [never] ? unknown : T;

/* @__NO_SIDE_EFFECTS__ */
export function memoize<TValue>(
fn: () => Promise<TValue>,
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {OutputFrom, Resolver, SchemaFrom} from './resolver';
import type {UnknownIfNever} from './utils';

import {memoizeWithKey} from './utils';

Expand All @@ -17,17 +16,15 @@ export type ValidationAdapter<TResolver extends Resolver> = <
>(
schema: TSchema,
) => Promise<
(
data: unknown,
) => Promise<ValidationResult<UnknownIfNever<OutputFrom<TResolver, TSchema>>>>
(data: unknown) => Promise<ValidationResult<OutputFrom<TResolver, TSchema>>>
>;

export type Validate<TResolver extends Resolver> = <
TSchema extends SchemaFrom<TResolver>,
>(
schema: TSchema,
data: unknown,
) => Promise<ValidationResult<UnknownIfNever<OutputFrom<TResolver, TSchema>>>>;
) => Promise<ValidationResult<OutputFrom<TResolver, TSchema>>>;

/* @__NO_SIDE_EFFECTS__ */
export function createValidate<TResolver extends Resolver>(
Expand All @@ -47,7 +44,7 @@ export type Assert<TResolver extends Resolver> = <
>(
schema: TSchema,
data: unknown,
) => Promise<UnknownIfNever<OutputFrom<TResolver, TSchema>>>;
) => Promise<OutputFrom<TResolver, TSchema>>;

/* @__NO_SIDE_EFFECTS__ */
export function createAssert<TResolver extends Resolver>(
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/wrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {InputFrom, OutputFrom, Resolver, SchemaFrom} from './resolver';
import type {UnknownIfNever} from './utils';
import type {Assert, Validate, ValidationIssue} from './validation';

export type TypeSchema<TOutput, TInput = TOutput> = {
Expand All @@ -16,10 +15,7 @@ export type Wrap<TResolver extends Resolver> = <
TSchema extends SchemaFrom<TResolver>,
>(
schema: TSchema,
) => TypeSchema<
UnknownIfNever<OutputFrom<TResolver, TSchema>>,
UnknownIfNever<InputFrom<TResolver, TSchema>>
>;
) => TypeSchema<OutputFrom<TResolver, TSchema>, InputFrom<TResolver, TSchema>>;

/* @__NO_SIDE_EFFECTS__ */
export function createWrap<TResolver extends Resolver>(
Expand Down
15 changes: 3 additions & 12 deletions packages/deepkit/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/deepkit/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type {IfDefined, Resolver} from '@typeschema/core';

export interface AdapterResolver extends Resolver {
base: IfDefined<Type, '@deepkit/type'>;
input: this['schema'] extends this['base'] ? unknown : never;
output: this['schema'] extends this['base'] ? unknown : never;
input: unknown;
output: unknown;
}
15 changes: 3 additions & 12 deletions packages/effect/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/effect/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export interface AdapterResolver extends Resolver {
base: IfDefined<Schema.AnyNoContext, '@effect/schema'>;
input: this['schema'] extends this['base']
? Schema.Encoded<this['schema']>
: never;
: unknown;
output: this['schema'] extends this['base']
? Schema.Type<this['schema']>
: never;
: unknown;
}
15 changes: 3 additions & 12 deletions packages/fastest-validator/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/fastest-validator/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type {ValidationSchema} from 'fastest-validator';

export interface AdapterResolver extends Resolver {
base: IfDefined<ValidationSchema, 'fastest-validator'>;
input: this['schema'] extends this['base'] ? unknown : never;
output: this['schema'] extends this['base'] ? unknown : never;
input: unknown;
output: unknown;
}
15 changes: 3 additions & 12 deletions packages/function/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/function/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export interface AdapterResolver extends Resolver {
input: this['schema'] extends this['base']
? keyof this['schema'] extends never
? Awaited<ReturnType<this['schema']>>
: never
: never;
: unknown
: unknown;
output: this['schema'] extends this['base']
? keyof this['schema'] extends never
? Awaited<ReturnType<this['schema']>>
: never
: never;
: unknown
: unknown;
}
Loading

0 comments on commit c732153

Please sign in to comment.