TypeScript: Mapped Type (Pick) and Intersection Type

This will show you how to use TypeScript's Mapped type, Pick, with the Intersection type. I was looking for an example of this online, and I may just be bad at making search queries, but I couldn't find it, so here it is for the Internets. I have a type called Dish, and I wanted … Continue reading TypeScript: Mapped Type (Pick) and Intersection Type

TypeScript: Property ‘response’ does not exist on type ‘{}’.ts(2339)

Property 'response' does not exist on type '{}. ts(2339)

Error I was using TypeScript, Axios, React, and Ant Design. I wanted to catch and display an error message if the API call returned an error. So in my catch block, I checked for a property on error. However, I got the error, "Property 'response' does not exist on type '{}'.ts(2339)." Here's a snippet of … Continue reading TypeScript: Property ‘response’ does not exist on type ‘{}’.ts(2339)

`object` (“[object Date]”) cannot be serialized as JSON

Error I was using Next.js 13, TypeScript, and MongoDB with Mongoose. I got the following error: Server Error Error: Error serializing .gasLog[1].createdAt returned from getServerSideProps in "/table". Reason: object ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types. This error happened while generating the page. Any console logs will be … Continue reading `object` (“[object Date]”) cannot be serialized as JSON

Type ‘Number’ is not assignable to type ‘ReactNode’.ts(2322)

Type 'Number' is not assignable to type 'ReactNode'.ts(2322)

Error I was using React and TypeScript, and I got the error, "Type 'Number' is not assignable to type 'ReactNode'.ts(2322)". I was trying to render a number in the JSX. Type 'Number' is not assignable to type 'ReactNode'.ts(2322) Why I received this error In React, you can only render components or strings inside JSX elements. … Continue reading Type ‘Number’ is not assignable to type ‘ReactNode’.ts(2322)

Next-auth: How to add more data to session

I’m using next v13.2.4 and next-auth v4.21.1. I was able to add more data to the client session by updating /pages/api/auth/[…nextauth.js] using the callbacks option. (It did not add more data to the server session). Here's an example [...nextauth.js] showing the addition of userId to the client session: import NextAuth from "next-auth"; export const authOptions … Continue reading Next-auth: How to add more data to session