Git Product home page Git Product logo

Comments (5)

felixfbecker avatar felixfbecker commented on June 20, 2024

It doesn't make much sense to declare a class just for the type if you're not gonna use it, you should use interfaces. One possible way is shown in the tests: https://github.com/louy/typed-sequelize/blob/master/4/test/define.ts

from sequelize.

felixfbecker avatar felixfbecker commented on June 20, 2024

If you want to use a class to type it, you need to pass typeof MyModel as the type parameter or you will get an instance back.

from sequelize.

pdeszynski avatar pdeszynski commented on June 20, 2024

@felixfbecker I should have firstly take a look into the tests directory... Thanks for the answer and yeah, it looks much better when using classes with init instead of define. I was hoping to achieve something like:

const myType = define<typeof MyModel>(...)

const inst1: MyModel = myType.findById('1');

const inst2: MyModel = new myType();
inst2.id;

Still this way I would have to export two things from a module to define a variable type somewhere else in a code

export default myType;
export { MyModel }

Thanks for help

from sequelize.

felixfbecker avatar felixfbecker commented on June 20, 2024

No problem. Is there any reason you want to use define()? All it does is create a class for you: https://github.com/sequelize/sequelize/blob/master/lib/sequelize.js#L343-L355

from sequelize.

pdeszynski avatar pdeszynski commented on June 20, 2024

No, there's no particular reason for it. I think using define is the most common way to define a model with Sequelize in JS, so I wanted it to be similar in TypeScript.

from sequelize.

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.