@hongminhee洪 民憙 (Hong Minhee) 아 Zod에서 영감을 받으신 거고 파라미터 파싱에 Zod를 쓰지는 않으시나보네요 😂
@xiniha 네네, Zod를 쓰는 건 아니고 Zod 스타일로 파싱 결과의 타입 구조를 선언할 수 있게 하려고 했습니다. 대충 아래와 같은 느낌이 되려나요?
const parser: Parser<
{
readonly options: { readonly type: "socket"; readonly socket: string } | {
readonly type: "listen";
readonly host: string;
readonly port: number;
};
} & {
readonly name: string;
readonly arguments: ReadonlyArray<string>;
}
> = and(
object({
options: or(
object("File socket options", {
type: constant("socket"),
socket: option("-s", "--socket", filePath()),
}),
object("Listening options", {
type: constant("listen"),
host: option("-h", "--host", string()),
port: option("-p", "--port", integer()),
}),
),
}),
object("Arguments", {
name: argument(string()),
files: multiple(argument(filePath()), 1),
}),
);
If you have a fediverse account, you can reply to this note from your own instance. Search https://hackers.pub/ap/notes/01985048-03de-73f8-ba89-e84289eef484 on your instance and reply to it.