[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