camo icon indicating copy to clipboard operation
camo copied to clipboard

Typescript definitions question

Open zinas opened this issue 9 years ago • 3 comments

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?

zinas avatar Dec 01 '16 10:12 zinas

I have the same problem as above

HenryNguyen5 avatar Mar 12 '17 23:03 HenryNguyen5

Use

let newUser = create<UserSchema>(...)

guysenpai avatar Apr 08 '17 10:04 guysenpai

I mean

let newUser = User.create<UserSchema>(...);

guysenpai avatar Apr 08 '17 10:04 guysenpai