Skip to content

Commit d30eefa

Browse files
committed
refac: change from string type to accurate DateISO type
1 parent 233a9aa commit d30eefa

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

components/events/Timetable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const AvailableDate = styled.div`
248248
`;
249249

250250
const NotAvailableDate = styled.div`
251-
background-color: ${(props) => props.theme.colors.block}};
251+
background-color: ${(props) => props.theme.colors.block};
252252
`;
253253

254254
const TimeUnit = styled.div`

lib/dataTransformer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* 생성
33
*/
44

5+
import type { DateISO } from "@dateTypes";
56
import type { Attendees } from "@eventsTypes";
67
import { Timestamp } from "firebase/firestore";
78

@@ -72,6 +73,8 @@ export const transformObjToValueLengthArray = <T>(obj: Record<string, T[]>) => {
7273
return Object.values(obj).map((obj) => obj.length);
7374
};
7475

75-
export const getMaxNumberOfAttendees = (attendees: Record<string, string[]>) => {
76+
export const getMaxNumberOfAttendees = (
77+
attendees: Record<DateISO, string[]>
78+
) => {
7679
return Math.max(...transformObjToValueLengthArray(attendees));
7780
};

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@hooks/*": ["lib/hooks/*"],
2828
"@eventsTypes": ["types/events"],
2929
"@newTypes": ["types/new"],
30+
"@dateTypes": ["types/date"],
3031
"@firebase/*": ["firebase/*"]
3132
}
3233
},

types/date/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* we use number instead of Digit because of ts2590 error
3+
* "Expression produces a union type that is too complex to represent. ts(2590)
4+
*
5+
* type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
6+
*/
7+
type FourNumbers = `${number}${number}${number}${number}`;
8+
type ThreeNumbers = `${number}${number}${number}`;
9+
type TwoNumbers = `${number}${number}`;
10+
11+
type Time =
12+
| "year"
13+
| "month"
14+
| "hour"
15+
| "day"
16+
| "minutes"
17+
| "seconds"
18+
| "milliseconds";
19+
20+
type getTimeFormat<T extends Time> = T extends "year"
21+
? FourNumbers
22+
: T extends "milliseconds"
23+
? ThreeNumbers
24+
: TwoNumbers;
25+
26+
/**
27+
* `2021-01-08`
28+
*/
29+
export type DateISODate =
30+
`${getTimeFormat<"year">}-${getTimeFormat<"month">}-${getTimeFormat<"day">}`;
31+
32+
/**
33+
* `14:42:34.678`
34+
*/
35+
export type DateISOTime =
36+
`${getTimeFormat<"hour">}:${getTimeFormat<"minutes">}:${getTimeFormat<"seconds">}.${getTimeFormat<"milliseconds">}`;
37+
38+
/**
39+
* `2021-01-08T14:42:34.678Z` (format: ISO 8601).
40+
*/
41+
export type DateISO = `${DateISODate}T${DateISOTime}Z`;

types/env.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ declare global {
66
NEXT_PUBLIC_DOMAIN_URL: string;
77
}
88
}
9-
interface Window {
10-
Kakao: any;
11-
}
129
}
1310

1411
export {};

types/global.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { DateISO } from "@dateTypes";
2+
declare global {
3+
interface Window {
4+
Kakao: any;
5+
}
6+
interface Date {
7+
toISOString(): DateISO;
8+
}
9+
}
10+
11+
export {};

0 commit comments

Comments
 (0)