File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,15 +8,27 @@ const formatDate = (date: Date): string | undefined => {
88 }
99} ;
1010
11- const badgeColors = {
12- Proposed : "primary" ,
13- Accepted : "success" ,
14- Rejected : "danger" ,
15- Deprecated : "warning" ,
16- Superseded : "warning" ,
11+ const AdrStatus = {
12+ Proposed : "Proposed" ,
13+ Accepted : "Accepted" ,
14+ Rejected : "Rejected" ,
15+ Deprecated : "Deprecated" ,
16+ Superseded : "Superseded" ,
17+ } as const ;
18+
19+ type AdrStatus = ( typeof AdrStatus ) [ keyof typeof AdrStatus ] ;
20+
21+ const badgeColors : Record < AdrStatus , string > = {
22+ [ AdrStatus . Proposed ] : "primary" ,
23+ [ AdrStatus . Accepted ] : "success" ,
24+ [ AdrStatus . Rejected ] : "danger" ,
25+ [ AdrStatus . Deprecated ] : "warning" ,
26+ [ AdrStatus . Superseded ] : "warning" ,
1727} ;
1828
19- const isBadgeColorKey = ( key : string ) : key is keyof typeof badgeColors => key in badgeColors ;
29+ function isAdrStatus ( value : unknown ) : value is AdrStatus {
30+ return typeof value === "string" && value in AdrStatus ;
31+ }
2032
2133interface AdrFrontMatter {
2234 adr : string ;
@@ -30,7 +42,7 @@ export default function AdrTable({
3042 frontMatter : AdrFrontMatter ;
3143} ) : React . JSX . Element {
3244 const { status } = frontMatter ;
33- const badgeColor = status && isBadgeColorKey ( status ) ? badgeColors [ status ] : "secondary" ;
45+ const badgeColor = isAdrStatus ( status ) ? badgeColors [ status ] : "secondary" ;
3446
3547 return (
3648 < table >
You can’t perform that action at this time.
0 commit comments