Skip to content

Commit 6a54711

Browse files
committed
chore: update docs and error mesasge
1 parent 3f22b88 commit 6a54711

8 files changed

+35
-33
lines changed

etc/types.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ export const int: Type<Branded<number, 'int'>, NumberTypeConfig>;
142142

143143
// @public (undocumented)
144144
export interface InterfaceMergeOptions {
145-
ignoreParsers?: true;
146-
ignoreValidations?: true;
147145
name?: string;
146+
omitParsers?: true;
147+
omitValidations?: true;
148148
}
149149

150150
// @public
@@ -410,7 +410,7 @@ export type PropertiesOfTypeTuple<Tuple> = Tuple extends [{
410410

411411
// @public
412412
export type PropertyInfo<T extends Type<unknown> = Type<unknown>> = {
413-
partial: boolean;
413+
optional: boolean;
414414
type: T;
415415
};
416416

markdown/types.interfacemergeoptions.ignorevalidations.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

markdown/types.interfacemergeoptions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ interface InterfaceMergeOptions
1212

1313
## Properties
1414

15-
| Property | Modifiers | Type | Description |
16-
| ------------------------------------------------------------------------ | --------- | ------ | ----------------------------------------------------------------------------------------------------------- |
17-
| [ignoreParsers?](./types.interfacemergeoptions.ignoreparsers.md) | | true | _(Optional)_ Suppress the error about existing custom parsers on one of the types that is being merged. |
18-
| [ignoreValidations?](./types.interfacemergeoptions.ignorevalidations.md) | | true | _(Optional)_ Suppress the error about existing custom validations on one of the types that is being merged. |
19-
| [name?](./types.interfacemergeoptions.name.md) | | string | _(Optional)_ The optional name for the type, uses a default TypeScript-like name if no name is given. |
15+
| Property | Modifiers | Type | Description |
16+
| -------------------------------------------------------------------- | --------- | ------ | -------------------------------------------------------------------------------------------------------- |
17+
| [name?](./types.interfacemergeoptions.name.md) | | string | _(Optional)_ The optional name for the type, uses a default TypeScript-like name if no name is given. |
18+
| [omitParsers?](./types.interfacemergeoptions.omitparsers.md) | | true | _(Optional)_ Suppress the error about existing custom parsers on one of the types that is being merged. |
19+
| [omitValidations?](./types.interfacemergeoptions.omitvalidations.md) | | true | _(Optional)_ When set, do not apply the custom validations from the base types onto the new merged type. |

markdown/types.interfacemergeoptions.ignoreparsers.md renamed to markdown/types.interfacemergeoptions.omitparsers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
22

3-
[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [InterfaceMergeOptions](./types.interfacemergeoptions.md) &gt; [ignoreParsers](./types.interfacemergeoptions.ignoreparsers.md)
3+
[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [InterfaceMergeOptions](./types.interfacemergeoptions.md) &gt; [omitParsers](./types.interfacemergeoptions.omitparsers.md)
44

5-
## InterfaceMergeOptions.ignoreParsers property
5+
## InterfaceMergeOptions.omitParsers property
66

77
Suppress the error about existing custom parsers on one of the types that is being merged.
88

99
**Signature:**
1010

1111
```typescript
12-
ignoreParsers?: true;
12+
omitParsers?: true;
1313
```
1414

1515
## Remarks
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [InterfaceMergeOptions](./types.interfacemergeoptions.md) &gt; [omitValidations](./types.interfacemergeoptions.omitvalidations.md)
4+
5+
## InterfaceMergeOptions.omitValidations property
6+
7+
When set, do not apply the custom validations from the base types onto the new merged type.
8+
9+
**Signature:**
10+
11+
```typescript
12+
omitValidations?: true;
13+
```
14+
15+
## Remarks
16+
17+
By default, custom validations (i.e. validations that are added to a type using [withValidation](./types.basetypeimpl.withvalidation.md) or [withConstraint](./types.basetypeimpl.withconstraint.md)<!-- -->) are reused when merging multiple interface types using [withOptional](./types.interfacetype.withoptional.md)<!-- -->, [withRequired](./types.interfacetype.withrequired.md) and [mergeWith](./types.interfacetype.mergewith.md)<!-- -->. Use this option to omit all custom validations in the resulting merged type.
18+
19+
Note that reuse of custom validations only works when no properties overlap between the types that are being merged. As long as the properties don't overlap we can be sure that the merged type is assignable to each of the original types (`A & B` is assignable to both `A` and `B`<!-- -->). Therefore, the validations are still safe to run, even though the type has been extended with additional properties.
20+
21+
When overlap is detected in the property-names of the types and any custom validation is encountered by Skunk Team types, an Error will be thrown. Use this option to ignore the custom validations and continue with the merge.

markdown/types.propertyinfo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Information about a single property of an object-like type including its optiona
1010

1111
```typescript
1212
type PropertyInfo<T extends Type<unknown> = Type<unknown>> = {
13-
partial: boolean;
13+
optional: boolean;
1414
type: T;
1515
};
1616
```

src/types/interface.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe(object, () => {
168168
const TypeA = object('TypeA', { prop: string }).withValidation(v => v.prop === 'the value');
169169
expect(() => TypeA.withRequired({ prop: number })).toThrowErrorMatchingInlineSnapshot(
170170
'"Error in TypeA.withRequired(): Merge operation not allowed because one of the types has custom validations applied ' +
171-
'and the following property is defined on both sides: <prop>, use `omitValidations` to suppress this error or ' +
171+
'and the following property is defined on both sides: <prop>, use `omitValidations` to prevent this error or ' +
172172
'remove the conflicting property."',
173173
);
174174

src/types/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class InterfaceType<Props extends Properties, ResultType>
245245
throw new Error(
246246
`Error in ${this.name}.${method}(): Merge operation not allowed because one of the types has custom ` +
247247
`validations applied and the following ${propertiesAre} defined on both sides: ${conflicts}, ` +
248-
'use `omitValidations` to suppress this error or remove the conflicting property.',
248+
'use `omitValidations` to prevent this error or remove the conflicting property.',
249249
);
250250
}
251251
}

0 commit comments

Comments
 (0)