diff --git a/modules/option/index.d.ts b/modules/option/index.d.ts new file mode 100644 index 00000000..a7700aa4 --- /dev/null +++ b/modules/option/index.d.ts @@ -0,0 +1,44 @@ +declare namespace Option { + interface Constructor { + readonly None: Option; + + Some: (value: NonNullable) => Option; + Wrap: (value: T) => Option; + Is: (value: unknown) => boolean; + Assert: (value: unknown) => void; + Deserialize: (data: SerializedOption) => Option; + } + + interface SerializedOption { + ClassName: "Option"; + Value?: T; + } + + interface Match { + Some: (value: T) => V; + None: () => V; + } +} + +interface Option { + Serialize(): Option.SerializedOption; + Match(match: Option.Match): V; + IsSome(): boolean; + IsNone(): boolean; + Expect(msg: string): T; + ExpectNone(msg: string): void; + Unwrap(): T; + UnwrapOr(defaultValue: T): T; + UnwrapOrElse(defaultFn: () => T): T; + And(optionB: Option): Option; + AndThen(andThenFn: (value: T) => V): Option; + Or(optionB: Option): Option | Option; + OrElse(orElseFn: (value: T) => V): Option; + XOr(optionB: Option): Option | Option; + Filter(predicate: (value: T) => boolean): Option; + Contains(value: T): boolean; +} + +declare const Option: Option.Constructor; + +export = Option;