Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript definitions question #87

Open
zinas opened this issue Dec 1, 2016 · 3 comments
Open

Typescript definitions question #87

zinas opened this issue Dec 1, 2016 · 3 comments

Comments

@zinas
Copy link

zinas commented Dec 1, 2016

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?

@HenryNguyen5
Copy link

I have the same problem as above

@guysenpai
Copy link

Use

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

@guysenpai
Copy link

I mean

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants