Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit56bab7c

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 parent8a37ba5 commit56bab7c

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 aboutcustomizing 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+
exporttype{ScreamingSnakeCaseasSnakeUpperCase}from'type-fest'
3+
exporttypeholder=1

‎src/spec/index.ts‎

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

6+
exporttype{SnakeUpperCase}from'./enhance'
7+
58
exporttype{TMetric}from'./metric'
69
exporttype{
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
exporttypeTResState='LOADING'|'DONE'|'EMPTY'
9898

99-
exporttypeTPaymentUsage='SENIOR'|'GirlsCodeTooPlan'|'DONATE'|'SPONSOR'
99+
exporttypeTPaymentUsage=
100+
|'SENIOR'
101+
|'GIRLS_CODE_TOO_PLAN'
102+
|'DONATE'
103+
|'SPONSOR'
100104
exporttypeTPaymentMethod='ALIPAY'|'WECHAT'
101105

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

186-
exporttypeTGtdType='BUG'|'FEATURE'|null
187-
exporttypeTGtdState='TODO'|'WIP'|'DONE'|null
190+
exporttypeTGtdType='BUG'|'FEATURE'|'DEFAULT'
191+
exporttypeTGtdState='TODO'|'WIP'|'DONE'|'DEFAULT'
188192

189193
exporttypeTTagMode='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
importtype{TGtdType,TGtdState}from'@/spec'
22

33
exportconstGTD_TYPE={
4-
FEATURE:'FEATURE'asTGtdType,
5-
BUG:'BUG'asTGtdType,
6-
DEFAULT:nullasTGtdType,
7-
}
4+
FEATURE:'FEATURE',
5+
BUG:'BUG',
6+
DEFAULT:'DEFAULT',
7+
}asRecord<Uppercase<TGtdType>,Uppercase<TGtdType>>
88

99
exportconstGTD_STATE={
10-
TODO:'TODO'asTGtdState,
11-
WIP:'WIP'asTGtdState,
12-
DONE:'DONE'asTGtdState,
13-
DEFAULT:nullasTGtdState,
14-
}
10+
TODO:'TODO',
11+
WIP:'WIP',
12+
DONE:'DONE',
13+
DEFAULT:'DEFAULT',
14+
}asRecord<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
importtype{TEmotionType}from'@/spec'
22

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

1212
exportdefaultEMOTION

‎utils/constant/layout.ts‎

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

33
exportconstUPVOTE_LAYOUT={
4-
DEFAULT:'default'asTUpvoteLayout,
5-
COMMENT:'comment'asTUpvoteLayout,
6-
ARTICLE:'article'asTUpvoteLayout,
7-
POST_LIST:'post-list'asTUpvoteLayout,
8-
BLOG_LIST:'blog-list'asTUpvoteLayout,
9-
WORKS_ARTICLE:'works-article'asTUpvoteLayout,
10-
WORKS_CARD:'works-card'asTUpvoteLayout,
11-
GUIDE_LIST:'guide-list'asTUpvoteLayout,
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+
}asRecord<SnakeUpperCase<TUpvoteLayout>,TUpvoteLayout>
1313

1414
exportconstholder=1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp