Back

Type 'URL' is missing the following properties from type 'Url': auth, path, slashes, query

  • 0
  • Web
Samrudh S
7 Apr, 2024, 23:35

The code is as below

TypeScript
import { ID } from "appwrite";
import { account, appwriteConfig, avatars, databases } from "./config";
import { Url } from "url";

export async function createUserAccount(user: INewUser) {

  try {
    
    const newAccount = await account.create(
     
      ID.unique(), 
      user.email,
      user.password,
      user.name
    );

    if (!newAccount) throw Error;
    const avatarUrl = avatars.getInitials(user.name);

    const newUser = await saveUserToDB({
      accountId: newAccount.$id,
      name: newAccount.name,
      email: newAccount.email,
      username: user.username,
      imageUrl: avatarUrl, //  THE ERROR POPS UP HERE
    });
    

    return newUser; 
  } catch (error) {
    console.log(error);
    return error;
  }
}

export async function saveUserToDB(user: {
  user: string;
  email: string;
  name: string;
  imageUrl: Url;
  username?: string; 
}) {
  try {
    const newUser = await databases.createDocument(
      appwriteConfig.databaseId,
      appwriteConfig.userCollectionId,
      ID.unique(),
      user
    );
    return newUser;
  } catch (error) {
    console.log(error);
  }
}```
     
The error pops up when assigning imageUrl property to avatarUrl as shown in the pic. 
The error as shown in the pic states states "Type 'URL' is missing the following properties from type 'Url': auth, path, slashes, queryts(2739) api.ts(45, 3): The expected type comes from property 'imageUrl' which is declared here on type '{ user: string; email: string; name: string; imageUrl: Url; username?: string | undefined; }' "

Both avatarUrl and imageUrl are of type url. But i am not able to add avatarUrl as imageUrl's property. How can i rectify this error ?
TL;DR
The developers are encountering an error when assigning `avatarUrl` as the `imageUrl` property due to a mismatch in the types. The issue arises from using 'Url' instead of 'URL'. By correcting the capitalization to 'URL' in the code, the error should be resolved.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more