I am using Typescript and I have defined a model and a schema (see code sample below). The problem is that the type checking can't see the attributes defined in the schema.
e.g.
const user = new User({ email: '[email protected]', name: 'Mark' });
// user.email -- it doesn't know about the email attribute
import dynamoose from './dynamoose';
const Schema = dynamoose.Schema;
const schema = new Schema({
email: {
type: String,
hashKey: true
},
name: { type: String }
});
const User = dynamoose.model('users', schema, { create: false });
const user = new User({ email: '[email protected]', name: 'Mark' });
// user.email -- it doesn't know about the email attribute
when I access user.email, in vscode, it displays Property 'email' does not exist on type 'Model
I expect the types to be included.
Operating System: Mac OSX
Operating System Version: Mojave
Node.js version (node -v): 8.13
NPM version: (npm -v): 6.4
Dynamoose version: 1.10.0
Dynamoose Plugins: none
-
@hweeks I was having the same issue as well and had to cast my models to custom interfaces I defined for them. It doesn't look like there's an easy solution to that problem with current Dynamoose typings?
yeah. the types need a lot of love. lemme take a pass later today at just fixing the typings. the use of generics isn鈥檛 quite right and it鈥檚 missing a lot of methods
I see this is quite old but for anyone looking for this, the model use generics and you need to inform the model:
export interface User extends Document {
name: string;
email: string;
}
export const UserSchema = dynamoose.schema({
email: {
type: String,
hashKey: true,
},
name: {
required: true,
type: String,
},
});
const UserModel: ModelType<User> = dynamoose.model<User>('user', UserSchema);
export default UserModel;
Most helpful comment
yeah. the types need a lot of love. lemme take a pass later today at just fixing the typings. the use of generics isn鈥檛 quite right and it鈥檚 missing a lot of methods