You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is a model im trying to create with a custom method called getPublicUser. It should just be a simple method that returns the public information of a user. But I'm having issues with defining the type of the method because I always get the typescript error:
Type 'UserDoc' does not satisfy the constraint 'Record<string, string | number | boolean | Integer | Point<Integer> | Date<Integer> | Time<Integer> | LocalTime<Integer> | ... 4 more ... | undefined>'.
Index signature for type 'string' is missing in type 'UserDoc'.
I don't quite understand this error but my guess would be that the constraint for the generic of the ModelFactory does not allow a function to be defined, only Record<string, string | number | boolean | Integer | Point<Integer> | Date<Integer> | Time<Integer> | LocalTime<Integer> | ... 4 more ... | undefined>.
This should either be a bug or I just declared the type of the method at the wrong place.
Please have a look here (press the "Typescript" tab). You need to something in the lines of:
typeIUser={phone?: string;phoneVerified?: boolean;
...
}// default value if it's emptytypeUserRelations=Object;interfaceIUserMethods{getPublicUser: (this: UserInstance)=>IPublicUser;}typeIUserStatics=Object;// import NeogmaInstancetypeUserInstance=NeogmaInstance<IUser,UserRelations,IUserMethods>;exportconstUser=ModelFactory<UserInstance,UserRelations,IUserStatics,IUserMethods>(// do not define any methods inside "User"
...
}// the following should have propert typing for for "this" and the return valueUser.prototype.getPublicUser=function(){// method body here}
Below is a model im trying to create with a custom method called
getPublicUser
. It should just be a simple method that returns the public information of a user. But I'm having issues with defining the type of the method because I always get the typescript error:I don't quite understand this error but my guess would be that the constraint for the generic of the
ModelFactory
does not allow a function to be defined, onlyRecord<string, string | number | boolean | Integer | Point<Integer> | Date<Integer> | Time<Integer> | LocalTime<Integer> | ... 4 more ... | undefined>
.This should either be a bug or I just declared the type of the method at the wrong place.
The text was updated successfully, but these errors were encountered: