Property 'authorId' does not exist on type 'Post[]'.

Coding along with the tutorial, and I came across this error I cant resolve. Portion in the video: 47:33 Code thus far:
import type { User } from "@clerk/nextjs/dist/api";
import { clerkClient } from "@clerk/nextjs/server";
import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

const filterUserForClient = (user: User) => {
return {
id: user.id,
username: user.username,
profileImageUrl: user.profileImageUrl}
}

export const postsRouter = createTRPCRouter({
getAll: publicProcedure.query(async ({ ctx }) => {
const posts = await ctx.prisma.post.findMany({
take: 100,
});

const users = (
await clerkClient.users.getUserList({
userId: posts.map((post) => post.authorId),
limit: 100,
})
).map(filterUserForClient);


console.log(users)

return posts.map((post) => ({
post,
author: users.find((user) => user.id === posts.authorId),
}));

// return posts;
}),
});
import type { User } from "@clerk/nextjs/dist/api";
import { clerkClient } from "@clerk/nextjs/server";
import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

const filterUserForClient = (user: User) => {
return {
id: user.id,
username: user.username,
profileImageUrl: user.profileImageUrl}
}

export const postsRouter = createTRPCRouter({
getAll: publicProcedure.query(async ({ ctx }) => {
const posts = await ctx.prisma.post.findMany({
take: 100,
});

const users = (
await clerkClient.users.getUserList({
userId: posts.map((post) => post.authorId),
limit: 100,
})
).map(filterUserForClient);


console.log(users)

return posts.map((post) => ({
post,
author: users.find((user) => user.id === posts.authorId),
}));

// return posts;
}),
});
4 Replies
whatplan
whatplan15mo ago
can you send your prisma schema db pushing + restarting vs code will often fix a lot of weird type errors
mapacheney
mapacheney15mo ago
You are trying to access .authorId on the whole array
whatplan
whatplan15mo ago
^ I didnt even read the code but yes if you hover posts you can see, it doesnt have authorId, as it is an array
ablc
ablc15mo ago
oh my god you're right, i was accessing the wrong thing being 1 letter off, posts instead of post my bad it was 3am :')