-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(frontend): Reactivityで型を明示するように #12791
Conversation
このPRによるapi.jsonの差分 差分はこちら--- base
+++ head
@@ -400,6 +400,10 @@
"type": "string",
"nullable": true
},
+ "shortName": {
+ "type": "string",
+ "nullable": true
+ },
"objectStorageS3ForcePathStyle": {
"type": "boolean",
"nullable": false
@@ -515,6 +519,7 @@
"maintainerEmail",
"maintainerName",
"name",
+ "shortName",
"objectStorageS3ForcePathStyle",
"privacyPolicyUrl",
"repositoryUrl",
@@ -31954,79 +31959,9 @@
"type": "array",
"nullable": false,
"items": {
- "properties": {
- "id": {
- "type": "string"
- },
- "firstRetrievedAt": {
- "type": "string"
- },
- "host": {
- "type": "string"
- },
- "usersCount": {
- "type": "number"
- },
- "notesCount": {
- "type": "number"
- },
- "followingCount": {
- "type": "number"
- },
- "followersCount": {
- "type": "number"
- },
- "isNotResponding": {
- "type": "boolean"
- },
- "isSuspended": {
- "type": "boolean"
- },
- "isBlocked": {
- "type": "boolean"
- },
- "softwareName": {
- "type": "string"
- },
- "softwareVersion": {
- "type": "string"
- },
- "openRegistrations": {
- "type": "boolean"
- },
- "name": {
- "type": "string"
- },
- "description": {
- "type": "string"
- },
- "maintainerName": {
- "type": "string"
- },
- "maintainerEmail": {
- "type": "string"
- },
- "isSilenced": {
- "type": "boolean"
- },
- "iconUrl": {
- "type": "string"
- },
- "faviconUrl": {
- "type": "string"
- },
- "themeColor": {
- "type": "string"
- },
- "infoUpdatedAt": {
- "type": "string",
- "nullable": true
- },
- "latestRequestReceivedAt": {
- "type": "string",
- "nullable": true
- }
- }
+ "type": "object",
+ "nullable": false,
+ "$ref": "#/components/schemas/FederationInstance"
}
},
"otherFollowersCount": {
@@ -32036,79 +31971,9 @@
"type": "array",
"nullable": false,
"items": {
- "properties": {
- "id": {
- "type": "string"
- },
- "firstRetrievedAt": {
- "type": "string"
- },
- "host": {
- "type": "string"
- },
- "usersCount": {
- "type": "number"
- },
- "notesCount": {
- "type": "number"
- },
- "followingCount": {
- "type": "number"
- },
- "followersCount": {
- "type": "number"
- },
- "isNotResponding": {
- "type": "boolean"
- },
- "isSuspended": {
- "type": "boolean"
- },
- "isBlocked": {
- "type": "boolean"
- },
- "softwareName": {
- "type": "string"
- },
- "softwareVersion": {
- "type": "string"
- },
- "openRegistrations": {
- "type": "boolean"
- },
- "name": {
- "type": "string"
- },
- "description": {
- "type": "string"
- },
- "maintainerName": {
- "type": "string"
- },
- "maintainerEmail": {
- "type": "string"
- },
- "isSilenced": {
- "type": "boolean"
- },
- "iconUrl": {
- "type": "string"
- },
- "faviconUrl": {
- "type": "string"
- },
- "themeColor": {
- "type": "string"
- },
- "infoUpdatedAt": {
- "type": "string",
- "nullable": true
- },
- "latestRequestReceivedAt": {
- "type": "string",
- "nullable": true
- }
- }
+ "type": "object",
+ "nullable": false,
+ "$ref": "#/components/schemas/FederationInstance"
}
},
"otherFollowingCount": {
@@ -32274,79 +32139,9 @@
"type": "array",
"nullable": false,
"items": {
- "properties": {
- "id": {
- "type": "string"
- },
- "firstRetrievedAt": {
- "type": "string"
- },
- "host": {
- "type": "string"
- },
- "usersCount": {
- "type": "number"
- },
- "notesCount": {
- "type": "number"
- },
- "followingCount": {
- "type": "number"
- },
- "followersCount": {
- "type": "number"
- },
- "isNotResponding": {
- "type": "boolean"
- },
- "isSuspended": {
- "type": "boolean"
- },
- "isBlocked": {
- "type": "boolean"
- },
- "softwareName": {
- "type": "string"
- },
- "softwareVersion": {
- "type": "string"
- },
- "openRegistrations": {
- "type": "boolean"
- },
- "name": {
- "type": "string"
- },
- "description": {
- "type": "string"
- },
- "maintainerName": {
- "type": "string"
- },
- "maintainerEmail": {
- "type": "string"
- },
- "isSilenced": {
- "type": "boolean"
- },
- "iconUrl": {
- "type": "string"
- },
- "faviconUrl": {
- "type": "string"
- },
- "themeColor": {
- "type": "string"
- },
- "infoUpdatedAt": {
- "type": "string",
- "nullable": true
- },
- "latestRequestReceivedAt": {
- "type": "string",
- "nullable": true
- }
- }
+ "type": "object",
+ "nullable": false,
+ "$ref": "#/components/schemas/FederationInstance"
}
},
"otherFollowersCount": {
@@ -32356,79 +32151,9 @@
"type": "array",
"nullable": false,
"items": {
- "properties": {
- "id": {
- "type": "string"
- },
- "firstRetrievedAt": {
- "type": "string"
- },
- "host": {
- "type": "string"
- },
- "usersCount": {
- "type": "number"
- },
- "notesCount": {
- "type": "number"
- },
- "followingCount": {
- "type": "number"
- },
- "followersCount": {
- "type": "number"
- },
- "isNotResponding": {
- "type": "boolean"
- },
- "isSuspended": {
- "type": "boolean"
- },
- "isBlocked": {
- "type": "boolean"
- },
- "softwareName": {
- "type": "string"
- },
- "softwareVersion": {
- "type": "string"
- },
- "openRegistrations": {
- "type": "boolean"
- },
- "name": {
- "type": "string"
- },
- "description": {
- "type": "string"
- },
- "maintainerName": {
- "type": "string"
- },
- "maintainerEmail": {
- "type": "string"
- },
- "isSilenced": {
- "type": "boolean"
- },
- "iconUrl": {
- "type": "string"
- },
- "faviconUrl": {
- "type": "string"
- },
- "themeColor": {
- "type": "string"
- },
- "infoUpdatedAt": {
- "type": "string",
- "nullable": true
- },
- "latestRequestReceivedAt": {
- "type": "string",
- "nullable": true
- }
- }
+ "type": "object",
+ "nullable": false,
+ "$ref": "#/components/schemas/FederationInstance"
}
},
"otherFollowingCount": {
@@ -48589,25 +48314,42 @@
"type": "object",
"nullable": false,
"properties": {
- "place": {
+ "id": {
"type": "string",
- "nullable": false
+ "nullable": false,
+ "format": "id",
+ "example": "xxxxxxxxxx"
},
"url": {
"type": "string",
"nullable": false,
"format": "url"
},
+ "place": {
+ "type": "string",
+ "nullable": false
+ },
+ "ratio": {
+ "type": "number",
+ "nullable": false
+ },
"imageUrl": {
"type": "string",
"nullable": false,
"format": "url"
+ },
+ "dayOfWeek": {
+ "type": "integer",
+ "nullable": false
}
},
"required": [
- "place",
+ "id",
"url",
- "imageUrl"
+ "place",
+ "ratio",
+ "imageUrl",
+ "dayOfWeek"
]
}
},
@@ -56438,7 +56180,19 @@
"application/json": {
"schema": {
"type": "object",
- "nullable": false
+ "nullable": false,
+ "properties": {
+ "sourceLang": {
+ "type": "string"
+ },
+ "text": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "sourceLang",
+ "text"
+ ]
}
}
} |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #12791 +/- ##
===========================================
- Coverage 79.79% 79.77% -0.02%
===========================================
Files 956 956
Lines 108807 108794 -13
Branches 8372 8372
===========================================
- Hits 86818 86789 -29
- Misses 21989 22005 +16 ☔ View full report in Codecov by Sentry. |
だったのが
みたいに初期値に空配列を入れるように変わってる箇所がいくつかあるけど、「値がまだfetchされていない」ことと「fetchしたけど結果が空だった」ことは区別される場合が多いから不具合が起きそう |
ので
みたいにするのが良さそう |
ごもっともです。修正します。 |
元々空配列だった部分についてはあえてそのままにしてあります🙏 |
@@ -62,7 +62,7 @@ const props = defineProps<{ | |||
}>(); | |||
|
|||
const note = ref<null | Misskey.entities.Note>(); | |||
const clips = ref(); | |||
const clips = ref<Misskey.entities.Clip[]>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const clips = ref<Misskey.entities.Clip[]>(); | |
const clips = ref<Misskey.entities.Clip[] | null>(null); |
かも
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは undefined
になるのでいいかなと思っていたのですが、null
に寄せたほうが良いでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
どっちでも良さそう
ただ undefined にする場合でも型は
Misskey.entities.Clip[] | undefined
にする必要がありそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
初期値の省略時は Ref<Misskey.entities.Clip[] | undefined>
で推論されるので、明示する必要はなさそうです。
https://ja.vuejs.org/guide/typescript/composition-api#typing-ref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ほーー
@@ -53,7 +54,7 @@ const props = withDefaults(defineProps<{ | |||
}); | |||
|
|||
const tab = ref(props.initialTab); | |||
const role = ref(); | |||
const role = ref<Misskey.entities.Role>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const role = ref<Misskey.entities.Role>(); | |
const role = ref<Misskey.entities.Role | null>(null); |
@@ -58,8 +59,8 @@ const { widgetProps, configure, save } = useWidgetPropsManager(name, | |||
emit, | |||
); | |||
|
|||
const list = ref(); | |||
const users = ref([]); | |||
const list = ref<Misskey.entities.UserList>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const list = ref<Misskey.entities.UserList>(); | |
const list = ref<Misskey.entities.UserList | null>(null); |
🙏🙏🙏🙏🙏 |
ご丁寧なレビューありがとうございました🙏 |
* refactor(frontend): Reactivityで型を明示するように * fix: プロパティの参照が誤っているのを修正 * fix: 初期化の値を空配列に書き換えていた部分をnullに置き換え
* refactor(frontend): Reactivityで型を明示するように * fix: プロパティの参照が誤っているのを修正 * fix: 初期化の値を空配列に書き換えていた部分をnullに置き換え
What
Vue の Reactivity を用いている箇所で、型を明示する必要がある箇所について(全てではないですが)ある程度修正を行いました。また、必要に応じてエンドポイントのスキーマを更新しました。
Why
ref()
、ref<any>()
はRef<any>
と推論されます。any
以外の型を明示することで、このようなany
をなるべく減らします。ref(null)
はRef<null>
と推論されるため、null
以外の値を代入しようとするとエラーが発生してしまいます。型を明示することで、このエラーをなるべく減らします1。ref([])
はRef<never[]>
と推論されるため、何かしらの値を代入しようとするとエラーが発生します。型を明示することで、このエラーをなるべく減らします。Additional info (optional)
Checklist
Footnotes
なお
ref(null)
については、修正しきれなかった箇所は(any
で検索した際に候補に出るようにしたいので)ref<any>(null)
へ書き換えを行っていますが、もしこれが不適切であればもとに戻します。 ↩