GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledge of TypeScript.
Hands-on real world projects that will help you exercise your knowledge of TypeScript. - GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledg...
github.com
당신을 위한 파일이 하나 더 있습니다.
여기에는 제 고객과 관련된 사건에서 제가 본 많은 Motion이 포함되어 있습니다.
그 Motion들을 기록하는 동안 나는 꽤 피곤해졌습니다.
TypeScript 타입이 없으며, 'motions' 배열의 많은 요소가 데이터에 오타가 있습니다.
까다로운 것은, 제출할 수 있는 몇 가지 다른 타입의 Motion이 있다는 것입니다.
다음을 구별하기 위해 타입에 일종의 타입 식별자 프로퍼티가 있어야 합니다:
- Status: allowed, denied 및 pending.
Allowed: 심의에 소요된 시간도 표시할 수 있습니다
Denied: 심의에 얼마나 많은 시간을 소비했는지, 그리고 그것이 사법부를 짜증나게 했는지를 나타낼 수도 있습니다
Pending: 심의에 소요될 것으로 예상되는 시간을 나타낼 수도 있습니다
- Step: post-trial 및 pre-tiral
pre-trial : dismiss, supression, venue 범주가 있습니다
post-trial : acquittal, correction, new trial 범주가 있습니다
## 파일
- "index.ts": 객체 타입 및 타입 어노테이션 작성
- "index.test.ts": 테스트
- "solution.ts": 솔루션 코드
// Write your types here! ✨
type MotionBase = {
from : "defendant" | "plaintiff"
reason : string
}
type PretrialMotion = MotionBase & {
step: "pre-trial"
classification : "dismiss" | "suppress" | "venue"
}
type PosttrialMotion = MotionBase & {
step: "post-trial"
classification : "acquittal" | "correction" | "new trial"
}
type TrialMotion = PretrialMotion | PosttrialMotion;
type AllowedMotion = TrialMotion & {
status : "allowed"
deliberationHours : number
}
type DeniedMotion = TrialMotion & {
annoyedJustice : boolean
status : "denied"
deliberationHours : number
}
type PendingMotion = TrialMotion & {
status : "pending"
estimatedDeliberationHours : number
}
type Motion = AllowedMotion | DeniedMotion | PendingMotion
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",
},
];
명시된 객체 타입 유니언을 통해 타입을 만드는 문제
타입 작성보다 문제 읽는 게 더 어렵다...
728x90
'Typescript > 러닝 타입스크립트 연습문제' 카테고리의 다른 글
(5장) Secret Secrets - 2.Dr. On (0) | 2023.04.14 |
---|---|
(5장) Secret Secrets - 1.Incoming Cipher (0) | 2023.04.13 |
(4장) Various Lawyerings - 2.Case Management (0) | 2023.04.12 |
(4장) Various Lawyerings - 1.Aviary Classification (0) | 2023.04.12 |
(3장 심화) The Narrow Trail (0) | 2023.04.06 |