nicoalbanese / kirimase

Build full-stack Next.js apps, incredibly fast
https://kirimase.dev
MIT License
2.64k stars 122 forks source link

Type 'Date' is not assignable to type 'string'. #28

Closed marvkr closed 1 year ago

marvkr commented 1 year ago

Hey in the Form component when creating a new schema that contains a date:

`const form = useForm<z.infer<typeof insertAmenitieParams>>({
    // latest Zod release has introduced a TS error with zodResolver
    // open issue: https://github.com/colinhacks/zod/issues/2663
    // errors locally but not in production
    resolver: zodResolver(insertAmenitieParams),
    defaultValues: amenitie ?? {
      name: "",
     imageUrl: "",
     listingId: "",
     category: "",
     createdAt: "",
     updatedAt: ""
    },`

throws a typescript error, which I fixed with:

const form = useForm<z.infer<typeof insertAmenitieParams>>({
    resolver: zodResolver(insertAmenitieParams),
    defaultValues: amenitie
      ? {
          ...amenitie,
          createdAt: amenitie.createdAt.toISOString(),
          updatedAt: amenitie.updatedAt.toISOString(),
        }
      : {
          name: "",
          imageUrl: "",
          listingId: "",
          category: "",
          createdAt: new Date().toISOString(),
          updatedAt: new Date().toISOString(),
        },
  });