Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeepUnbranded type: later bailout by compiler and migration to expect-type #105

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions etc/types.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ export function createType<Impl extends BaseTypeImpl<any, any>>(impl: Impl, over
export type CustomMessage<T, E = void> = undefined | string | ((got: string, input: T, explanation: E) => string);

// @public
export type DeepUnbranded<T> = T extends ReadonlyArray<unknown> ? {
[P in keyof T & number]: DeepUnbranded<T[P]>;
} : T extends Record<string, unknown> ? Omit<{
[P in keyof T]: DeepUnbranded<T[P]>;
}, typeof brands> : Unbranded<T>;
export type DeepUnbranded<T> = T extends readonly [any, ...any[]] | readonly [] ? UnbrandValues<Unbranded<T>> : T extends Array<infer E> ? Array<DeepUnbranded<E>> : T extends ReadonlyArray<infer E> ? ReadonlyArray<DeepUnbranded<E>> : T extends Record<string, unknown> ? UnbrandValues<Unbranded<T>> : Unbranded<T>;

// @public
export const designType: unique symbol;
Expand Down Expand Up @@ -460,6 +456,9 @@ export { reportError_2 as reportError }
// @public
export type Result<T> = Success<T> | Failure;

// @public (undocumented)
export type SimpleAcceptVisitor<ResultType, TypeConfig> = <R>(type: SimpleType<ResultType, TypeConfig>, visitor: Visitor<R>) => R;

// @public
export class SimpleType<ResultType, TypeConfig> extends BaseTypeImpl<ResultType, TypeConfig> {
accept<R>(visitor: Visitor<R>): R;
Expand All @@ -473,8 +472,6 @@ export class SimpleType<ResultType, TypeConfig> extends BaseTypeImpl<ResultType,

// @public (undocumented)
export interface SimpleTypeOptions<ResultType, TypeConfig> {
// Warning: (ae-forgotten-export) The symbol "SimpleAcceptVisitor" needs to be exported by the entry point index.d.ts
//
// (undocumented)
acceptVisitor?: SimpleAcceptVisitor<ResultType, TypeConfig>;
// (undocumented)
Expand Down Expand Up @@ -564,6 +561,11 @@ export type TypeOfProperties<T extends Properties> = {
// @public
export type Unbranded<T> = T extends WithBrands<infer Base, any> ? Base : T;

// @public (undocumented)
export type UnbrandValues<T> = {
[P in keyof T]: DeepUnbranded<T[P]>;
};

// @public (undocumented)
export const undefinedType: TypeImpl<LiteralType<undefined>>;

Expand Down
19 changes: 8 additions & 11 deletions markdown/types.deepunbranded.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ Unbrand a given type (recursive).
**Signature:**

```typescript
type DeepUnbranded<T> = T extends ReadonlyArray<unknown>
? {
[P in keyof T & number]: DeepUnbranded<T[P]>;
}
type DeepUnbranded<T> = T extends readonly [any, ...any[]] | readonly []
? UnbrandValues<Unbranded<T>>
: T extends Array<infer E>
? Array<DeepUnbranded<E>>
: T extends ReadonlyArray<infer E>
? ReadonlyArray<DeepUnbranded<E>>
: T extends Record<string, unknown>
? Omit<
{
[P in keyof T]: DeepUnbranded<T[P]>;
},
typeof brands
>
? UnbrandValues<Unbranded<T>>
: Unbranded<T>;
```

**References:** [DeepUnbranded](./types.deepunbranded.md)<!-- -->, [brands](./types.brands.md)<!-- -->, [Unbranded](./types.unbranded.md)
**References:** [UnbrandValues](./types.unbrandvalues.md)<!-- -->, [Unbranded](./types.unbranded.md)<!-- -->, [DeepUnbranded](./types.deepunbranded.md)
2 changes: 2 additions & 0 deletions markdown/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Runtime type-validation with derived TypeScript types.
| [PropertiesOfTypeTuple](./types.propertiesoftypetuple.md) | |
| [PropertyInfo](./types.propertyinfo.md) | Information about a single property of an object-like type including its optionality. |
| [Result](./types.result.md) | The result of a type validation. |
| [SimpleAcceptVisitor](./types.simpleacceptvisitor.md) | |
| [Simplify](./types.simplify.md) | Flatten the type output to improve type hints as shown in editors. |
| [StringViolation](./types.stringviolation.md) | The supported additional checks on string types. |
| [The](./types.the.md) | Obtains the TypeScript type of the given runtime Type-checker. Aka [TypeOf](./types.typeof.md)<!-- -->. |
Expand All @@ -132,6 +133,7 @@ Runtime type-validation with derived TypeScript types.
| [TypeOf](./types.typeof.md) | Obtains the TypeScript type of the given runtime Type-checker. Aka [The](./types.the.md)<!-- -->. |
| [TypeOfProperties](./types.typeofproperties.md) | Translates the type of a Properties-object into the proper TypeScript type to be used in user-code. |
| [Unbranded](./types.unbranded.md) | Unbrand a given type (not recursive). |
| [UnbrandValues](./types.unbrandvalues.md) | |
| [unknownArray](./types.unknownarray.md) | Built-in validator that accepts all arrays. |
| [unknownRecord](./types.unknownrecord.md) | Built-in validator that accepts all objects (<code>null</code> is not accepted). |
| [ValidationDetails](./types.validationdetails.md) | Information about the performed validation for error-reporting. |
Expand Down
13 changes: 13 additions & 0 deletions markdown/types.simpleacceptvisitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [SimpleAcceptVisitor](./types.simpleacceptvisitor.md)

## SimpleAcceptVisitor type

**Signature:**

```typescript
type SimpleAcceptVisitor<ResultType, TypeConfig> = <R>(type: SimpleType<ResultType, TypeConfig>, visitor: Visitor<R>) => R;
```

**References:** [SimpleType](./types.simpletype.md)<!-- -->, [Visitor](./types.visitor.md)
2 changes: 1 addition & 1 deletion markdown/types.simpletypeoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface SimpleTypeOptions<ResultType, TypeConfig>

| Property | Modifiers | Type | Description |
| -------------------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------- | ------------ |
| [acceptVisitor?](./types.simpletypeoptions.acceptvisitor.md) | | SimpleAcceptVisitor&lt;ResultType, TypeConfig&gt; | _(Optional)_ |
| [acceptVisitor?](./types.simpletypeoptions.acceptvisitor.md) | | [SimpleAcceptVisitor](./types.simpleacceptvisitor.md)<!-- -->&lt;ResultType, TypeConfig&gt; | _(Optional)_ |
| [autoCaster?](./types.simpletypeoptions.autocaster.md) | | [BaseTypeImpl](./types.basetypeimpl.md)<!-- -->&lt;ResultType, TypeConfig&gt;\['autoCaster'\] | _(Optional)_ |
| [combineConfig?](./types.simpletypeoptions.combineconfig.md) | | [BaseTypeImpl](./types.basetypeimpl.md)<!-- -->&lt;ResultType, TypeConfig&gt;\['combineConfig'\] | _(Optional)_ |
| [enumerableLiteralDomain?](./types.simpletypeoptions.enumerableliteraldomain.md) | | [BaseTypeImpl](./types.basetypeimpl.md)<!-- -->&lt;ResultType, TypeConfig&gt;\['enumerableLiteralDomain'\] | _(Optional)_ |
Expand Down
15 changes: 15 additions & 0 deletions markdown/types.unbrandvalues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [UnbrandValues](./types.unbrandvalues.md)

## UnbrandValues type

**Signature:**

```typescript
type UnbrandValues<T> = {
[P in keyof T]: DeepUnbranded<T[P]>;
};
```

**References:** [DeepUnbranded](./types.deepunbranded.md)
10 changes: 10 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"expect-type": "^1.1.0",
"jest": "^29.7.0",
"jest-extended": "^4.0.1",
"npm-run-all": "^4.1.5",
Expand Down
Loading