Skip to content

Commit 763e34a

Browse files
fix: resolve TypeScript error with categoryNames type mismatch
- Fixed categoryNames type from (string | undefined)[] to string[] in scripts router - Added proper type filtering and assertion in getScriptCardsWithCategories - Added missing ScriptCard import in scripts router - Ensures type safety for categoryNames property throughout the application
1 parent 0074b43 commit 763e34a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/server/api/routers/scripts.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { scriptManager } from "~/server/lib/scripts";
44
import { githubJsonService } from "~/server/services/githubJsonService";
55
import { localScriptsService } from "~/server/services/localScripts";
66
import { scriptDownloaderService } from "~/server/services/scriptDownloader";
7+
import type { ScriptCard } from "~/types/script";
78

89
export const scriptsRouter = createTRPCRouter({
910
// Get all available scripts
@@ -160,15 +161,15 @@ export const scriptsRouter = createTRPCRouter({
160161
// Enhance cards with category information and additional script data
161162
const cardsWithCategories = cards.map(card => {
162163
const script = scripts.find(s => s.slug === card.slug);
163-
const categoryNames = script?.categories?.map(id => categoryMap[id]).filter(Boolean) ?? [];
164+
const categoryNames: string[] = script?.categories?.map(id => categoryMap[id]).filter((name): name is string => typeof name === 'string') ?? [];
164165

165166
return {
166167
...card,
167168
categories: script?.categories ?? [],
168-
categoryNames,
169+
categoryNames: categoryNames,
169170
// Add date_created from script
170171
date_created: script?.date_created,
171-
};
172+
} as ScriptCard;
172173
});
173174

174175
return { success: true, cards: cardsWithCategories, metadata };

0 commit comments

Comments
 (0)