Skip to content

Commit 7d213d7

Browse files
committed
Simpler result type
1 parent 09f30f6 commit 7d213d7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/synopt.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ type Options = {
4141
[key: string]: boolean | string | string[];
4242
};
4343

44-
type ErrorResult = { ok: false; error: string };
45-
type OkResult<T> = { ok: true; options: T };
46-
type Result<T> = OkResult<T> | ErrorResult;
44+
type Result<T> = { ok: false; error: string } | { ok: true; options: T };
4745

48-
const Ok = <T>(options: T): OkResult<T> => ({ ok: true, options });
46+
const Ok = <T>(options: T): Result<T> => ({ ok: true, options });
4947

50-
const Err = (error: string): ErrorResult => ({
48+
const Err = <T>(error: string): Result<T> => ({
5149
ok: false,
5250
error,
5351
});
@@ -140,13 +138,13 @@ const createCommand = (name?: string): Command => {
140138
* @param {object} [options] - Options for this declaration. Example `{ boolean: true, required: true }`
141139
* @return {Command} The option declaration representation object
142140
*/
143-
option: (...args): Command => {
141+
option: (...args: DeclarationTuple): Command => {
144142
const declaration = parseDeclaration(args);
145143
ensureNamesUnique(declaration, state.optionDeclarations);
146144
state.optionDeclarations.push(declaration);
147145
return command;
148146
},
149-
parse: (args): Result<Options> => {
147+
parse: (args: string[]): Result<Options> => {
150148
const options: Options = {};
151149

152150
try {

0 commit comments

Comments
 (0)