Coder Social home page Coder Social logo

Comments (6)

szokodiakos avatar szokodiakos commented on July 20, 2024

Hello! What kind of error do you get, and can you please include your whole file?

from typegoose.

halleyxu avatar halleyxu commented on July 20, 2024

thanks for replay~
the error print with webstrom is
Error:(86, 26) TS2345:Argument of type '{ title: string; }' is not assignable to parameter of type 'Job'.
Property 'startedAt' is missing in type '{ title: string; }'.

if add {id:"",getModelForClass:null} the error disappear

this.previousJobs.push({ title: 'Janitor',id:"",getModelForClass:null}); noerror
this.previousJobs.push({ title: 'Janitor'}); error

from typegoose.

szokodiakos avatar szokodiakos commented on July 20, 2024

I think the problem is that you forgot to pass the template parameter to InstanceType: InstanceType<User>. Let me know if this fixes the error

from typegoose.

halleyxu avatar halleyxu commented on July 20, 2024

@instanceMethod addJob(this: InstanceType<User>) { this.previousJobs.push({startedAt:new Date(),id:"xx",getModelForClass:null}); this.save(); }

need add "id:"xx",getModelForClass:null" it's about class Job and InstanceType does not matter

from typegoose.

szokodiakos avatar szokodiakos commented on July 20, 2024

Okay i will try to reproduce the problem.

from typegoose.

vinczedani avatar vinczedani commented on July 20, 2024

Hi @halleyxu
I looked into your issue. Based on your report I changed the "demo" code for the tests. We had some issue on a typescript level that mad the Job interface require the getModelForClass and the startedAt.
Please look at the files changed here
The main changes are that the typegoose extend is removed from subDocument (this caused the getModelForClass requirement) and the '?' mark on the typeScript definition of the Job class (this made startedAt required when pushing it to Job array). But please note that this way on the Job subClass you wont be able to create instanceMethods or staticMethods.
I hope it helps. If you feel like this answer resolved your question please close the issue.
If you have any more question feel free to ask it.
Thanks,
Daniel

from typegoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.