From 0f8686dd5782fc03485db5939b148e7de0bcdf86 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:13:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor(`ApQuestionService.ts`):=20non-null=20?= =?UTF-8?q?assertion=E3=82=92=E6=B6=88=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/activitypub/models/ApQuestionService.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index de8ad0ae0e..35abdaf24b 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -47,11 +47,17 @@ export class ApQuestionService { throw new Error('invalid question'); } - const choices = question[multiple ? 'anyOf' : 'oneOf']! - .map((x, i) => x.name!); + const choices = question[multiple ? 'anyOf' : 'oneOf'] + ?.map((x) => x.name) + .filter((x): x is string => typeof x === 'string') + ?? []; - const votes = question[multiple ? 'anyOf' : 'oneOf']! - .map((x, i) => x.replies && x.replies.totalItems || x._misskey_votes || 0); + const votes = question[multiple ? 'anyOf' : 'oneOf'] + ?.map((x) => { + if (x.replies) return x.replies.totalItems; + if (x._misskey_votes) return x._misskey_votes; + return 0; + }); return { choices,