Closed JonasHiltl closed 3 years ago
Hey Jonas,
Please have a look here (press the "Typescript" tab). You need to something in the lines of:
type IUser = {
phone?: string;
phoneVerified?: boolean;
...
}
// default value if it's empty
type UserRelations = Object;
interface IUserMethods {
getPublicUser: (this: UserInstance) => IPublicUser;
}
type IUserStatics = Object;
// import NeogmaInstance
type UserInstance = NeogmaInstance<IUser, UserRelations, IUserMethods>;
export const User = ModelFactory<UserInstance, UserRelations, IUserStatics, IUserMethods>(
// do not define any methods inside "User"
...
}
// the following should have propert typing for for "this" and the return value
User.prototype.getPublicUser = function () {
// method body here
}
Please me know if you got it working
Oh, that makes sense, I never clicked the typescript tab. That's awesome. Thanks a lot for your work creating this library.
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.