Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Dec 24, 2023
1 parent e8c0a15 commit 6cba452
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
54 changes: 53 additions & 1 deletion docs/modules/Schema.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Added in v1.0.0
- [TaggedRequest (interface)](#taggedrequest-interface)
- [TaggedRequest (namespace)](#taggedrequest-namespace)
- [Any (type alias)](#any-type-alias)
- [withDefaultConstructor](#withdefaultconstructor)
- [combinators](#combinators)
- [array](#array)
- [attachPropertySignature](#attachpropertysignature)
Expand Down Expand Up @@ -362,8 +363,10 @@ Added in v1.0.0
- [To (type alias)](#to-type-alias)
- [ToAsserts (type alias)](#toasserts-type-alias)
- [StructFields (type alias)](#structfields-type-alias)
- [ToOptionalConstructorKeys (type alias)](#tooptionalconstructorkeys-type-alias)
- [ToOptionalKeys (type alias)](#tooptionalkeys-type-alias)
- [ToStruct (type alias)](#tostruct-type-alias)
- [ToStructConstructor (type alias)](#tostructconstructor-type-alias)
- [from](#from)
- [optional](#optional-1)
- [propertySignatureAnnotations](#propertysignatureannotations)
Expand Down Expand Up @@ -1641,7 +1644,13 @@ export declare const Class: <Self>() => <Fields extends StructFields>(
fields: Fields
) => [unknown] extends [Self]
? "Missing `Self` generic - use `class Self extends Class<Self>()({ ... })`"
: Class<Simplify<FromStruct<Fields>>, Simplify<ToStruct<Fields>>, Simplify<ToStruct<Fields>>, Self, Data.Case>
: Class<
Simplify<FromStruct<Fields>>,
Simplify<ToStruct<Fields>>,
Simplify<ToStructConstructor<Fields>>,
Self,
Data.Case
>
```
Added in v1.0.0
Expand Down Expand Up @@ -1831,6 +1840,19 @@ export type Any =
Added in v1.0.0
## withDefaultConstructor
**Signature**
```ts
export declare const withDefaultConstructor: <From, To>(
s: Schema<From, To>,
makeDefault: () => To
) => ConstructorPropertyDescriptor<From, To>
```
Added in v1.0.0
# combinators
## array
Expand Down Expand Up @@ -4214,11 +4236,24 @@ export type StructFields = Record<
| Schema<never, never>
| PropertySignature<any, boolean, any, boolean>
| PropertySignature<never, boolean, never, boolean>
| ConstructorPropertyDescriptor<any> // TODO: variation for PropertySignature too
>
```

Added in v1.0.0

## ToOptionalConstructorKeys (type alias)

**Signature**

```ts
export type ToOptionalConstructorKeys<Fields> = {
[K in keyof Fields]: Fields[K] extends ConstructorPropertyDescriptor<any, any> ? K : never
}[keyof Fields]
```

Added in v1.0.0

## ToOptionalKeys (type alias)

**Signature**
Expand Down Expand Up @@ -4247,6 +4282,22 @@ export type ToStruct<Fields extends StructFields> = {

Added in v1.0.0

## ToStructConstructor (type alias)

**Signature**

```ts
export type ToStructConstructor<Fields extends StructFields> = {
readonly [K in Exclude<keyof Fields, ToOptionalKeys<Fields> | ToOptionalConstructorKeys<Fields>>]: Schema.To<
Fields[K]
>
} & { readonly [K in ToOptionalKeys<Fields>]?: Schema.To<Fields[K]> } & {
readonly [K in ToOptionalConstructorKeys<Fields>]?: Schema.To<Fields[K]>
}
```

Added in v1.0.0

## from

**Signature**
Expand Down Expand Up @@ -4312,6 +4363,7 @@ export declare const propertySignatureAnnotations: (
| Schema<never, never>
| PropertySignature<any, boolean, any, boolean>
| PropertySignature<never, boolean, never, boolean>
| ConstructorPropertyDescriptor<any, any>
>(
self: S
) => S extends Schema<infer I, infer A> ? PropertySignature<I, false, A, false> : S
Expand Down
10 changes: 10 additions & 0 deletions src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4331,18 +4331,28 @@ interface ConstructorPropertyDescriptor<From, To = From> extends Schema<From, To
make: () => To
}
/**
* @category classes
* @since 1.0.0
*/
export const withDefaultConstructor = <From, To>(
s: Schema<From, To>,
makeDefault: () => To
): ConstructorPropertyDescriptor<From, To> => {
return Object.assign({}, s, { make: makeDefault })
}
/**
* @since 1.0.0
*/
export type ToOptionalConstructorKeys<Fields> = {
[K in keyof Fields]: Fields[K] extends ConstructorPropertyDescriptor<any, any> ? K
: never
}[keyof Fields]
/**
* @since 1.0.0
*/
export type ToStructConstructor<Fields extends StructFields> =
& {
readonly [
Expand Down

0 comments on commit 6cba452

Please sign in to comment.