Back
Type 'URL' is missing the following properties from type 'Url': auth, path, slashes, query
- 0
- Web
Samrudh S
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. Recommended threads
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- apple exchange code to token
hello guys, im new here 🙂 I have created a project and enabled apple oauth, filled all data (client id, key id, p8 file itself etc). I generate oauth code form...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...