Skip to content

Commit

Permalink
Merge c6bd7e3 into 1dc50ef
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain authored Sep 27, 2024
2 parents 1dc50ef + c6bd7e3 commit 824caea
Show file tree
Hide file tree
Showing 16 changed files with 4,188 additions and 18 deletions.
Binary file added packages/ssz/package.tgz
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/ssz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export {OptionalType} from "./type/optional";
export {VectorBasicType} from "./type/vectorBasic";
export {VectorCompositeType} from "./type/vectorComposite";
export {ListUintNum64Type} from "./type/listUintNum64";
export {StableContainerType} from "./type/stableContainer";
export {ProfileType} from "./type/profile";

// Base types
export {ArrayType} from "./type/array";
Expand Down
13 changes: 13 additions & 0 deletions packages/ssz/src/type/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {CompositeType, isCompositeType} from "./composite";
import {addLengthNode, getLengthFromRootNode} from "./arrayBasic";
/* eslint-disable @typescript-eslint/member-ordering */

export type NonOptionalType<T extends Type<unknown>> = T extends OptionalType<infer U> ? U : T;
export type NonOptionalFields<Fields extends Record<string, Type<unknown>>> = {
[K in keyof Fields]: NonOptionalType<Fields[K]>;
};

export type OptionalOpts = {
typeName?: string;
};
Expand Down Expand Up @@ -258,3 +263,11 @@ export class OptionalType<ElementType extends Type<unknown>> extends CompositeTy
return this.elementType.equals(a, b);
}
}

export function isOptionalType(type: Type<unknown>): type is OptionalType<Type<unknown>> {
return type instanceof OptionalType;
}

export function toNonOptionalType<T extends Type<unknown>>(type: T): NonOptionalType<T> {
return (isOptionalType(type) ? type.elementType : type) as NonOptionalType<T>;
}
Loading

0 comments on commit 824caea

Please sign in to comment.