[Leaning Typescript ๐Ÿฆœ] various-lawyerings

๐Ÿ‘ฉโ€๐ŸŽ“ Various Lawyerings

Hello, fellow lawyer. Iโ€™m glad youโ€™ve chosen to join me in preparing to engage in legal battle. As you can see, I require your assistance in developing TypeScript projects to manage my files for this most important case.

์•ˆ๋…•, ๋™๋ฃŒ ๋ณ€ํ˜ธ์‚ฌ์•ผ.
์ด๋ฒˆ ๋ฒ•์ • ์‚ฌ๊ฑด์„ ๋‚˜์™€ ํ•จ๊ป˜ ์ค€๋น„ํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค๋‹ˆ ์ •๋ง ๊ธฐ์˜๋‹ค.
๋ณด๋‹ค์‹œํ”ผ, ์•„์ฃผ ์ค‘์š”ํ•œ ์ผ€์ด์Šค๋ฅผ ์œ„ํ•œ ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๋Š” ์ง€๊ธˆ ๊ฐœ๋ฐœ์ค‘์ธ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ๋„ˆ๊ฐ€ ๋„์™€์คฌ์Œ ์ข‹๊ฒ ๋‹ค์ž‰.

  • ํƒ€์ž… ์ธํ„ฐํŽ˜์ด์Šค๋ง๊ณ , ํƒ€์ž… ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.

๐ŸŽ“ Step 1: Aviary Classification

As a world-renowned expert in bird law, it is my duty to properly educate the court on the characteristics of various birds and related bird information. I cannot uphold my critical task if my bird files are not in proper order.

I require you to write an object type describing a Bird type for my array of birds. Please be as specific as possible for types when possible. Any property other than name whose values are strings should be a union of unions of string literals.

โ–ช ์š”์•ฝ: ์ƒˆ ์ •๋ณด๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๊ฐ์ฒด ํƒ€์ž…์„ ๊ฐ€๋Šฅํ•œ ๊ตฌ์ฒด์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ค˜. name๋ง๊ณ ๋„ ๊ฐ’์ด string์ธ ํ”„๋กœํผํ‹ฐ๋Š” string ๋ฆฌํ„ฐ๋Ÿด ์œ ๋‹ˆ์–ธ ํƒ€์ž…์ด ๋˜์–ด์•ผํ•ด

๐Ÿ“„ ๋ฌธ์ œ ์ฝ”๋“œ

birds๋ฐฐ์—ด์˜ ์†์„ฑ๋“ค์ด ๊ฐ์ฒด๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ฐ์ฒด๋“ค์˜ ํƒ€์ž…์„ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

// Write your Bird type here! โœจ
export const birds = [
  {
    dangerous: true,
    diet: "omnivore",
    name: "White-Throated Magpie-Jay",
    noisy: true,
  },
  {
    diet: "omnivore",
    intelligent: true,
    name: "Eurasian Magpie",
  },
  {
    diet: "carnivore",
    name: "Yellow-Billed Blue Magpie",
    noisy: true,
  },
  {
    intelligent: true,
    diet: "omnivore",
    name: "American Crow",
  },
];

๐Ÿ“„ ํ’€์ด๊ณผ์ •

๊ณตํ†ต๋œ ์†์„ฑ๋“ค์„ ๋นผ์ฃผ๊ณ  ์„œ๋กœ ๋‹ค๋ฅธ ๊ฒฝ์šฐ์˜ ์†์„ฑ๋“ค์„ ์œ ๋‹ˆ์–ธ ํƒ€์ž…์œผ๋กœ ์ƒ์„ฑํ•ด ๊ต์ฐจ ํƒ€์ž…์œผ๋กœ ๋ฌถ์–ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

error๋Š” ์—†์–ด์กŒ์ง€๋งŒ ์ด๊ฒŒ ์š”๊ตฌ์‚ฌํ•ญ๋Œ€๋กœ ํ•œ๊ฒŒ ๋งž๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.

type Bird = { name: string; diet: string } & (
  | { dangerous: boolean; noisy: boolean }
  | { diet: string }
  | { noisy: boolean }
  | { intelligent: boolean }
);

โœ” ์ •๋‹ต

export type Bird = {
  dangerous?: boolean,
  diet: "carnivore" | "omnivore",
  intelligent?: boolean,
  name: string,
  noisy?: boolean,
};

์—ญ์‹œ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค. ๊ต์ฐจ ํƒ€์ž…๋ง๊ณ  ์„ ํƒ์  ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋‹ˆ ํ›จ์”ฌ ๊ฐ€๋…์„ฑ์žˆ๋„ค์š”.

๊ต์ฐจ ํƒ€์ž…์„ ์•Œ๊ธฐ ์ „์—๋Š” ์ด๋ ‡๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ์—ˆ๋Š”๋ฐ ๊ต์ฐจ ํƒ€์ž…์„ ๊ณต๋ถ€ํ•˜๋‹ˆ ์• ๋จผ๊ณณ์— ์–ถ๋งค์—ฌ ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

์—ญ์‹œ ์ฝ”๋“œ๋Š” ์‚ฌ๋žŒ์ด ๋ˆˆ์œผ๋กœ ์ฝ๊ธฐ ์ข‹๊ฒŒ ์งœ์•ผํ•ฉ๋‹ˆ๋‹ค.

๐ŸŽ“ Step 2: Case Management

Very good, very good. My birds are classified correctly. I thank you.
Next, I have the opposite type of task for you to tackle. I have created a Case type for you and have a cases array. But, the elements in cases vary in format and do not always match up with the Case type. Please correct cases โ€“ without changing the Case type.

โ–ช ์š”์•ฝ: ์•„์ฃผ ๋ง˜์— ๋“œ๋Š”๊ตฌ๋งŒ. ์ด๋ฒˆ์—” ๋ฐ˜๋Œ€๋กœ ๋‚ด์ฃผ์ง€. ํƒ€์ž… Case๋ฅผ ๋ฐ”๊พธ์ง€ ๋ง๊ณ  ๋ฐฐ์—ด cases๋ฅผ ๋ฐ”๊ฟ”์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด ๋ด๋ผ!

๐Ÿ“„ ๋ฌธ์ œ ์ฝ”๋“œ

์ด๋ฒˆ์—๋Š” ํƒ€์ž…์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ฃผ์–ด์ง„ ๋ฐฐ์—ด ๋ฐ์ดํ„ฐ์ธ cases๋ฅผ ๊ณ ์ณ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

export type Case = {
  court: "state" | "federal";
  decided: Date;
  defendant: string;
  id: string | string[];
  plaintiff: string;
  title: string;
};

export const cases: Case[] = [
  {
    court: "federal",
    decided: new Date("February 18, 1986"),
    defendant: ["Glynn Batson", "and", "Southplains Land Corporation"],
    id: 841710,
    plaintiff: "United States of America",
    title: "United States v. Batson",
  },
  {
    court: "state",
    decided: "April 17, 1992",
    defendant: "Bradford Marine, Inc",
    id: ["90-6372-CIV", "90-6599-CIV"],
    plaintiff: "Lyn C. Noble",
    title: "Noble v. Bradford Marine, Inc",
  },
  {
    amusing: true,
    court: "NY state",
    defendant: "PepsiCo, Inc.",
    decided: {
      on: new Date("August 5, 1999"),
    },
    ids: ["96-cv-5320", "96-cv-9069"],
    plaintiff: "John Leonard",
    title: "Leonard v. Pepsico, Inc.",
  },
];

๐Ÿ“„ ํ•ด๊ฒฐ ๊ณผ์ •

์ฃผ์–ด์ง„ ํƒ€์ž… Case์— ๋งž๊ฒŒ ๋ฐฐ์—ด cases๋ฅผ ๋ฐ”๊พธ์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

Case์— ์—†๋Š” ์†์„ฑ์€ ์•„์˜ˆ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.

export type Case = {
  court: "state" | "federal";
  decided: Date;
  defendant: string;
  id: string | string[];
  plaintiff: string;
  title: string;
};

export const cases: Case[] = [
  {
    court: "federal",
    decided: new Date("February 18, 1986"),
    defendant: "Glynn Batson and Southplains Land Corporation",
    id: "841710",
    plaintiff: "United States of America",
    title: "United States v. Batson",
  },
  {
    court: "state",
    decided: new Date("1992-04-17"),
    defendant: "Bradford Marine, Inc",
    id: ["90-6372-CIV", "90-6599-CIV"],
    plaintiff: "Lyn C. Noble",
    title: "Noble v. Bradford Marine, Inc",
  },
  {
    court: "state",
    defendant: "PepsiCo, Inc.",
    decided: new Date("August 5, 1999"),
    id: ["96-cv-5320", "96-cv-9069"],
    plaintiff: "John Leonard",
    title: "Leonard v. Pepsico, Inc.",
  },
];

์ •๋‹ต ์ฝ”๋“œ์™€ ์ผ์น˜ํ•ฉ๋‹ˆ๋‹ค :)

๐Ÿ“„ Step 3: Making Arguments

Well done, dear chap! Well done indeed. I have but one more file for you. It contains the many motions I have seen in cases involving my clients. I must admit, Iโ€™d grown quite weary while jotting down those motions. It is missing TypeScript types, and many elements in the motions array have typos in their data. The tricky thing is, there are a few different types of motions that can be filed. There should be some kind of discriminating indicator property on the types to distinguish between:

  • Status: allowed, denied, and pending. Within those types:
    • Allowed: it may also indicate how many hours it spent in deliberation
    • Denied: it may also indicate how many hours it spent in deliberation, and whether it annoyed the justice
    • Pending: it may also indicate how many hours itโ€™s estimated to spent in deliberation
  • Step: post-trial and pre-trial. Within those types:
    • Pre-trial: I only noted dismissals, suppressions, and venue changes
    • Post-trial: I only noted acquittals, corrections, and new trials

โ–ช ์•„์ฃผ ์ž˜ํ–ˆ๊ตฐ, ๋…€์„. ๋‚˜ ์ •๋ง ํ”ผ๊ณคํ•˜๋‹คโ€ฆ ๋‚ด ํด๋ผ์ด์–ธํŠธ ์‚ฌ๊ฑด๋“ค์—์„œ ์‚ฌ๋ผ์ง„ ํƒ€์ž…์„ ์ฐพ๊ณ  ์˜คํƒ€ ์ข€ ๊ณ ์ณ์ฃผ๋ผ.. ์—ฌ๊ธฐ ๊ตฌ๋ณ„ํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœํผํ‹ฐ๋“ค์ด ์žˆ์–ด.(๋งํ•ด๋ฒ„๋ฆฐ ๋ฒˆ์—ญ์ž…๋‹ˆ๋‹ค.)

๐Ÿ“„ ๋ฌธ์ œ ์ฝ”๋“œ

๋ฐฐ์—ด motions ์š”์†Œ๋ฅผ ์ด๋ฃจ๋Š” ๊ฐ์ฒด์˜ ํƒ€์ž…์„ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•˜๋„ค์š”.

// Write your types here! โœจ

export const motions: Motion[] = [
  {
    annoyedJustice: true,
    classification: "acquittal",
    deliberationHours: 1,
    from: "defendant",
    reason: "The heretofore document had dried ink on it.",
    status: "denied",
    step: "post-trial",
  },
  {
    annoyedJustice: true,
    classification: "correction",
    deliberationHours: 2.5,
    from: "plaintiff",
    reason: "The tenant has ninety days to vacate.",
    status: "denied",
    step: "post-trial",
  },
  {
    classification: "suppress",
    deliberationHours: 4,
    from: "plaintiff",
    reason: "Frank was never allowed in the house.",
    status: "allowed",
    step: "pre-trial",
  },
  {
    classification: "new trial",
    estimatedDeliberationHours: 3,
    from: "defendant",
    reason: "The duel's been accepted. There's no backing out. That's the law.",
    status: "pending",
    step: "post-trial",
  },
  {
    annoyedJustice: false,
    classification: "dismiss",
    deliberationHours: 0.5,
    from: "plaintiff",
    reason:
      "It seems like you have a tenuous grasp on the English language in general.",
    status: "denied",
    step: "pre-trial",
  },
  {
    annoyedJustice: true,
    classification: "correction",
    deliberationHours: 1.5,
    from: "defendant",
    reason: "Fillibuster?",
    status: "denied",
    step: "post-trial",
  },
  {
    annoyedJustice: true,
    classification: "venue",
    deliberationHours: 0.25,
    from: "defendant",
    reason: "A time was never specified for the duel.",
    status: "denied",
    step: "pre-trial",
  },
  {
    annoyedJustice: true,
    classification: "correction",
    deliberationHours: 5,
    from: "plaintiff",
    reason: "He's making a few good points!",
    status: "denied",
    step: "post-trial",
  },
];

๐Ÿ“„ ํ’€์ด ๊ณผ์ •

์ด๋ฒˆ ๋ฌธ์ œ๋Š” ์ œ ์˜์–ด ์‹ค๋ ฅ์— ํ•œ๊ณ„๊ฐ€ ๋Š๊ปด์กŒ์Šต๋‹ˆ๋‹ค.

์ฃผ์–ด์ง„ ์ง€๋ฌธ์„ ๋ณด๊ณ  ๋ฌธ์ œ๊ฐ€ ์ž˜ ์ดํ•ด๊ฐ€ ๊ฐ€์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

์ฒ˜์Œ์œผ๋กœ ๋ชปํ’€์—ˆ๋˜ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค..

์šฐ์„  ๊ฐ์ฒด์˜ ๊ณตํ†ต๋œ ์†์„ฑ๋“ค์„ ๊ฐ€์ง€๊ณ  ๋ฒ ์ด์Šค ํƒ€์ž…์„ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.

export type MotionBase = {
  from: "defendant" | "plaintiff";
  reason: string;
};

์ดํ›„, ์ง€๋ฌธ์—์„œ ์ฃผ์–ด์ง„ ์š”๊ตฌ์‚ฌํ•ญ์— ๋งž๊ฒŒ ๋‘๊ฐ€์ง€ ํƒ€์ž…์„ ๋ถ„๋ฅ˜ํ•ฉ๋‹ˆ๋‹ค.

export type PreTrialMotion = MotionBase & {
  classification: "dismiss" | "suppress" | "venue";
  step: "pre-trial";
};

export type PostTrialMotion = MotionBase & {
  classification: "acquittal" | "correction" | "new trial";
  step: "post-trial";
};

์ด๋ ‡๊ฒŒ ์žฌํŒ ์œ ํ˜•์— ๋”ฐ๋ฅธ ํƒ€์ž… TrialMotion์„ ์œ ๋‹ˆ์–ธ ํƒ€์ž…์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

export type TrialMotion = PostTrialMotion | PreTrialMotion;

์ด์ œ ๊ฐ ์ƒํƒœ์— ๋งž๊ฒŒ ํƒ€์ž…์„ ๋ถ„๋ฅ˜ํ•˜๊ณ  ์œ ๋‹ˆ์–ธ ํƒ€์ž…์œผ๋กœ ํ•ฉ์ณ ์ตœ์ข… ํƒ€์ž…์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

export type AllowedMotion = TrialMotion & {
  deliberationHours: number;
  status: "allowed";
};

export type DeniedMotion = TrialMotion & {
  annoyedJustice: boolean;
  deliberationHours: number;
  status: "denied";
};

export type PendingMotion = TrialMotion & {
  estimatedDeliberationHours: number;
  status: "pending";
};

export type Motion = AllowedMotion | DeniedMotion | PendingMotion;

์˜์–ด ๊ณต๋ถ€๋ฅผ ์ข€ ๋” ํ•ด์•ผ๊ฒ ๋„ค์š”.

์ •๋‹ต ์ฝ”๋“œ๋ฅผ ๋ณด๊ธฐ ์ „๊นŒ์ง„ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ์‚ฌ์‹ค ๊ฐ์ด ์ž˜ ์žกํžˆ์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

์—ญ์‹œ ์˜์–ด๋Š” ๊ผญ ๊ณต๋ถ€ํ•ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ ์ถœ์ฒ˜

Leave a comment