Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 56bab7c

Browse files
authored
refactor(types): enhance type system (#1299)
* refactor(type): use Record for json constant * refactor(type): use Record for json constant * chore(eslint): clean up import type error * chore(type): extract third lib to spec
1 parent 8a37ba5 commit 56bab7c

File tree

14 files changed

+113
-78
lines changed

14 files changed

+113
-78
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module.exports = {
88
'@groupher/eslint-config-web',
99
'eslint:recommended',
1010
'plugin:@typescript-eslint/recommended',
11+
// see: https://stackoverflow.com/a/56696478/4050784
12+
'plugin:import/typescript',
1113
],
1214
// extends: ['@groupher/eslint-config-web'],
1315
settings: {

package-lock.json

Lines changed: 26 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
"shelljs": "0.8.4",
162162
"standard-version": "^8.0.1",
163163
"start-server-and-test": "1.12.1",
164+
"type-fest": "^2.12.2",
164165
"typescript": "^4.2.3"
165166
}
166167
}

src/spec/article.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export type TUpvoteLayout =
210210
| 'comment'
211211
| 'article'
212212
| 'post-list'
213+
| 'blog-list'
213214
| 'works-article'
214215
| 'works-card'
215216
| 'guide-list'

src/spec/enhance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// see: https://github.com/sindresorhus/type-fest#template-literal-types
2+
export type { ScreamingSnakeCase as SnakeUpperCase } from 'type-fest'
3+
export type holder = 1

src/spec/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { TRootStore as RootStoreType } from '@/stores/RootStore'
2+
23
import type { TArticle } from './article'
34
import type { TCommunity } from './community'
45

6+
export type { SnakeUpperCase } from './enhance'
7+
58
export type { TMetric } from './metric'
69
export type {
710
TSIZE,

src/spec/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ export type TTabItem = {
9696

9797
export type TResState = 'LOADING' | 'DONE' | 'EMPTY'
9898

99-
export type TPaymentUsage = 'SENIOR' | 'GirlsCodeTooPlan' | 'DONATE' | 'SPONSOR'
99+
export type TPaymentUsage =
100+
| 'SENIOR'
101+
| 'GIRLS_CODE_TOO_PLAN'
102+
| 'DONATE'
103+
| 'SPONSOR'
100104
export type TPaymentMethod = 'ALIPAY' | 'WECHAT'
101105

102106
export type TFlexRule =
@@ -183,7 +187,7 @@ export type TModelineType =
183187
| 'search'
184188
| 'more'
185189

186-
export type TGtdType = 'BUG' | 'FEATURE' | null
187-
export type TGtdState = 'TODO' | 'WIP' | 'DONE' | null
190+
export type TGtdType = 'BUG' | 'FEATURE' | 'DEFAULT'
191+
export type TGtdState = 'TODO' | 'WIP' | 'DONE' | 'DEFAULT'
188192

189193
export type TTagMode = 'default' | 'label'

utils/constant/GTD.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { TGtdType, TGtdState } from '@/spec'
22

33
export const GTD_TYPE = {
4-
FEATURE: 'FEATURE' as TGtdType,
5-
BUG: 'BUG' as TGtdType,
6-
DEFAULT: null as TGtdType,
7-
}
4+
FEATURE: 'FEATURE',
5+
BUG: 'BUG',
6+
DEFAULT: 'DEFAULT',
7+
} as Record<Uppercase<TGtdType>, Uppercase<TGtdType>>
88

99
export const GTD_STATE = {
10-
TODO: 'TODO' as TGtdState,
11-
WIP: 'WIP' as TGtdState,
12-
DONE: 'DONE' as TGtdState,
13-
DEFAULT: null as TGtdState,
14-
}
10+
TODO: 'TODO',
11+
WIP: 'WIP',
12+
DONE: 'DONE',
13+
DEFAULT: 'DEFAULT',
14+
} as Record<Uppercase<TGtdState>, Uppercase<TGtdState>>

utils/constant/emotion.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { TEmotionType } from '@/spec'
22

33
const EMOTION = {
4-
DOWNVOTE: 'downvote' as TEmotionType,
5-
BEER: 'beer' as TEmotionType,
6-
HEART: 'heart' as TEmotionType,
7-
CONFUSED: 'confused' as TEmotionType,
8-
POPCORN: 'popcorn' as TEmotionType,
9-
PILL: 'pill' as TEmotionType,
10-
}
4+
DOWNVOTE: 'downvote',
5+
BEER: 'beer',
6+
HEART: 'heart',
7+
CONFUSED: 'confused',
8+
POPCORN: 'popcorn',
9+
PILL: 'pill',
10+
} as Record<Uppercase<TEmotionType>, TEmotionType>
1111

1212
export default EMOTION

utils/constant/layout.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import type { TUpvoteLayout } from '@/spec'
1+
import type { TUpvoteLayout, SnakeUpperCase } from '@/spec'
22

33
export const UPVOTE_LAYOUT = {
4-
DEFAULT: 'default' as TUpvoteLayout,
5-
COMMENT: 'comment' as TUpvoteLayout,
6-
ARTICLE: 'article' as TUpvoteLayout,
7-
POST_LIST: 'post-list' as TUpvoteLayout,
8-
BLOG_LIST: 'blog-list' as TUpvoteLayout,
9-
WORKS_ARTICLE: 'works-article' as TUpvoteLayout,
10-
WORKS_CARD: 'works-card' as TUpvoteLayout,
11-
GUIDE_LIST: 'guide-list' as TUpvoteLayout,
12-
}
4+
DEFAULT: 'default',
5+
COMMENT: 'comment',
6+
ARTICLE: 'article',
7+
POST_LIST: 'post-list',
8+
BLOG_LIST: 'blog-list',
9+
WORKS_ARTICLE: 'works-article',
10+
WORKS_CARD: 'works-card',
11+
GUIDE_LIST: 'guide-list',
12+
} as Record<SnakeUpperCase<TUpvoteLayout>, TUpvoteLayout>
1313

1414
export const holder = 1

0 commit comments

Comments
 (0)