camo
camo copied to clipboard
Typescript definitions question
I am trying to define a very simple class, like this:
import { Document, DocumentSchema, SchemaTypeExtended } from 'camo';
export interface UserSchema extends DocumentSchema {
email: string;
password: string;
}
export class User extends Document<UserSchema> {
public email: SchemaTypeExtended = String;
public password: SchemaTypeExtended = String;
}
Now, lets assume, I am trying to create a new user:
let newUser = User.create({ email: 'A', password: 'B' });
console.log(newUser.email) // prints 'A', but typescript throws error
newUser.save().then(user => {
console.log(user.email); // prints 'A' and typescript doesn't complain
});
Any idea how I can fix the error?
I have the same problem as above
Use
let newUser = create<UserSchema>(...)
I mean
let newUser = User.create<UserSchema>(...);