Next.js Discord

Discord Forum

Type Not Letting Me Assign Null Value

Unanswered
German yellowjacket posted this in #help-forum
Open in Discord
German yellowjacketOP
I have this type
type BucketListPlace = {
   id: string;
   formattedAddress: string;
   displayName: string;
   location: {
      lat: number;
      lng: number;
   };
   dateAdded: string;
   dateVisited: string | null;
   googleMapsURI: string | null;
   websiteURI: string;
};

And it gives this issue for dateVisited, googleMapsURI, websiteURI
Type 'null' is not assignable to type 'string | undefined'
   const cleanedPlace: BucketListPlace = {
      id: place.id,
      formattedAddress: place.formattedAddress as string,
      displayName: place.displayName as string,
      location: {
         lat: place.location?.lat() ?? 0,
         lng: place.location?.lng() ?? 0,
      },
      dateAdded: new Date().toISOString(),
      dateVisited: null,
      googleMapsURI: place.googleMapsURI || null,
      websiteURI: place.websiteURI || null,
   };

0 Replies