From 76faec21158e34b0f29efbbc15f4778d212ee202 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Feb 2023 11:46:08 +0900 Subject: [PATCH] refactor: fix types --- packages/backend/src/core/AchievementService.ts | 2 +- packages/backend/src/logger.ts | 2 +- packages/backend/src/misc/i18n.ts | 3 +-- .../backend/src/server/api/endpoints/i/claim-achievement.ts | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/AchievementService.ts b/packages/backend/src/core/AchievementService.ts index 5fd9c451ce..2ebee0f7e0 100644 --- a/packages/backend/src/core/AchievementService.ts +++ b/packages/backend/src/core/AchievementService.ts @@ -5,7 +5,7 @@ import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; import { CreateNotificationService } from '@/core/CreateNotificationService.js'; -const ACHIEVEMENT_TYPES = [ +export const ACHIEVEMENT_TYPES = [ 'notes1', 'notes10', 'notes100', diff --git a/packages/backend/src/logger.ts b/packages/backend/src/logger.ts index 87f9b12313..91039098f1 100644 --- a/packages/backend/src/logger.ts +++ b/packages/backend/src/logger.ts @@ -45,7 +45,7 @@ export default class Logger { } const time = dateFormat(new Date(), 'HH:mm:ss'); - const worker = cluster.isPrimary ? '*' : cluster.worker.id; + const worker = cluster.isPrimary ? '*' : cluster.worker!.id; const l = level === 'error' ? important ? chalk.bgRed.white('ERR ') : chalk.red('ERR ') : level === 'warning' ? chalk.yellow('WARN') : diff --git a/packages/backend/src/misc/i18n.ts b/packages/backend/src/misc/i18n.ts index e304a8adac..b1c727827d 100644 --- a/packages/backend/src/misc/i18n.ts +++ b/packages/backend/src/misc/i18n.ts @@ -11,10 +11,9 @@ export class I18n> { // string にしているのは、ドット区切りでのパス指定を許可するため // なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも - @bindThis public t(key: string, args?: Record): string { try { - let str = key.split('.').reduce((o, i) => o[i], this.locale) as string; + let str = key.split('.').reduce((o, i) => o[i], this.locale as any) as string; if (args) { for (const [k, v] of Object.entries(args)) { diff --git a/packages/backend/src/server/api/endpoints/i/claim-achievement.ts b/packages/backend/src/server/api/endpoints/i/claim-achievement.ts index 52ae5475b6..d7109c6953 100644 --- a/packages/backend/src/server/api/endpoints/i/claim-achievement.ts +++ b/packages/backend/src/server/api/endpoints/i/claim-achievement.ts @@ -1,7 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; -import { AchievementService } from '@/core/AchievementService.js'; +import { AchievementService, ACHIEVEMENT_TYPES } from '@/core/AchievementService.js'; export const meta = { requireCredential: true, @@ -10,7 +10,7 @@ export const meta = { export const paramDef = { type: 'object', properties: { - name: { type: 'string' }, + name: { type: 'string', enum: ACHIEVEMENT_TYPES }, }, required: ['name'], } as const;