I am getting some type errors in my Next.JS work using typescript and prisma.
This is the relevant information regarding my case.
model Game {
id Int @id @default(autoincrement())
upvote_count Int @default(0)
title String
studio String?
thumbnail String?
blockchain String?
description String?
tagline String?
isTeam Boolean @default(true)
fundraising String?
links String?
genres Genre[] @relation("GameGenre")
gallery String?
stage DevStatus?
ownerId Int?
owner Users? @relation(fields:[ownerId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([title, studio], name:"title_studio")
}
model Genre {
genre String @id @unique
description String?
games Game[] @relation("GameGenre")
}
enum DevStatus {
preProduction
production
playableDemo
live
}
so the npx prisma generate runs fine but I get type errors thrown in my seed.ts file
interface Genres {
genre: string;
description?: string;
}
interface Genre {
where: { name: Genres };
create: { name: Genres };
}
enum DevStatus {
preProduction = "preProduction",
production = "production",
playableDemo = "playableDemo",
live = "live",
}
interface Game {
title: string;
studio: string;
thumbnail?: string;
blockchain?: string;
description?: string;
tagline?: string;
isTeam?: boolean;
fundraising?: string;
links?: string;
genres?: Genre | string[];
gallery?: string;
stage?: string;
}
async function seedGames() {
const games: Game[] = DATA;
for (const row of games) {
const existingRow = await prisma.game.findUnique({
where: {
title_studio: {
title: row.title,
studio: row.studio,
},
},
});
if (!existingRow) {
//genreData = ["genre", "genre"]
//{ where: { name: "RPG" }, create: { name: "RPG" } }
try {
const gameGenres = row.genres;
const genresData = connectOrCreateFieldsFromArrayOfStrings(gameGenres);
const resp = await prisma.game.create({
data: {
title: row.title,
studio: row.studio,
thumbnail: row.thumbnail,
description: row.description,
blockchain: row.blockchain,
tagline: row.tagline,
isTeam: row.isTeam,
fundraising: row.fundraising,
links: row.links,
gallery: row.gallery,
stage: row.stage,
genres: {
connectOrCreate: genresData,
},
},
});
} catch (error) {
console.log("caught error while creating a game in db", error);
}
} else {
console.log(
`Skipping creation of ${row.title} and ${row.studio}, already exists in database.`
);
}
}
prisma.$disconnect();
}
if anyone has any advice please let me know!
I was trying to run seed.ts but I get these error messages
prisma/seed.ts:107:15 - error TS2322: Type 'object' is not assignable to type 'Enumerable<GenreCreateOrConnectWithoutGamesInput> | undefined'.
107 connectOrCreate: genresData,
~~~~~~~~~~~~~~~
prisma/seed.ts:113:13 - error TS2322: Type 'string | undefined' is not assignable to type 'DevStatus | null | undefined'.
Type 'string' is not assignable to type 'DevStatus | null | undefined'.
113 stage: row.stage,
~~~~~
node_modules/.prisma/client/index.d.ts:5455:5
5455 stage?: DevStatus | null
~~~~~
The expected type comes from property 'stage' which is declared here on type '(Without<GameCreateInput, GameUncheckedCreateInput> & GameUncheckedCreateInput) | (Without<...> & GameCreateInput)'
prisma/seed.ts:128:50 - error TS7006: Parameter 'arrOfStrings' implicitly has an 'any' type.
128 function connectOrCreateFieldsFromArrayOfStrings(arrOfStrings): object {
~~~~~~~~~~~~
prisma/seed.ts:129:28 - error TS7006: Parameter 'genre' implicitly has an 'any' type.
129 return arrOfStrings.map((genre) => ({
~~~~~
at createTSError (/Users/andrewchoi/Desktop/workspace/thecoreloop/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/Users/andrewchoi/Desktop/workspace/thecoreloop/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/Users/andrewchoi/Desktop/workspace/thecoreloop/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/Users/andrewchoi/Desktop/workspace/thecoreloop/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/Users/andrewchoi/Desktop/workspace/thecoreloop/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
at Object.require.extensions.<computed> [as .ts] (/Users/andrewchoi/Desktop/workspace/thecoreloop/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1133:32)
at Function.Module._load (node:internal/modules/cjs/loader:972:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
diagnosticCodes: [ 2322, 2322, 7006, 7006 ]
}