Skip to content

Commit 5ef5124

Browse files
committed
Remove unused types and format files
1 parent 74999a9 commit 5ef5124

12 files changed

Lines changed: 1163 additions & 768 deletions

File tree

src/arg.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
1-
import { KnownKey, MapUnion } from "./types"
1+
import { KnownKey, MapUnion } from "./types";
22

3-
type ArgType = "required" | "optional"
3+
type ArgType = "required" | "optional";
44

5-
type ArgTypeToValue<T extends ArgType> = MapUnion<T, {
6-
required: string,
7-
optional: string | undefined,
8-
}>[T]
5+
type ArgTypeToValue<T extends ArgType> = MapUnion<
6+
T,
7+
{
8+
required: string;
9+
optional: string | undefined;
10+
}
11+
>[T];
912

1013
export type ParsedArgs<Args extends Record<string, Arg>> = {
11-
[K in keyof Args as KnownKey<K>]: Args[K] extends Arg<infer T> ? ArgTypeToValue<T> : never
12-
}
14+
[K in keyof Args as KnownKey<K>]: Args[K] extends Arg<infer T>
15+
? ArgTypeToValue<T>
16+
: never;
17+
};
1318

1419
export class Arg<T extends ArgType = ArgType> {
15-
public constructor(private _type: T) { }
16-
17-
public optional(): Arg<"optional"> {
18-
this._type = "optional" as T
19-
return this as Arg<"optional">
20-
}
21-
22-
public static toObject(arg: Arg) {
23-
return {
24-
type: arg._type,
25-
}
26-
}
27-
28-
public static toString(arg: Arg, name: string) {
29-
if (arg._type === "required") return `<${name}>`
30-
else return `[${name}]`
31-
}
20+
public constructor(private _type: T) {}
21+
22+
public optional(): Arg<"optional"> {
23+
this._type = "optional" as T;
24+
return this as Arg<"optional">;
25+
}
26+
27+
public static toObject(arg: Arg) {
28+
return {
29+
type: arg._type,
30+
};
31+
}
32+
33+
public static toString(arg: Arg, name: string) {
34+
if (arg._type === "required") return `<${name}>`;
35+
else return `[${name}]`;
36+
}
3237
}
3338

3439
export function arg() {
35-
return new Arg("required")
40+
return new Arg("required");
3641
}

0 commit comments

Comments
 (0)