B
B
bitalikrr2019-09-26 22:30:29
typescript
bitalikrr, 2019-09-26 22:30:29

I can't figure out what this entry means?

I'm starting to learn typeScript, I
came across such code and I just can't google how to understand it

// Need to declare the static model so `findOne` etc. use correct types.
type MyModelStatic = typeof Model & {
  new (values?: object, options?: BuildOptions): MyModel;
}

Take the code from the sequelize documentation
Specifically, I don’t understand what the sign & means
Why is typeof there
And what kind of instance is created here new (values?: object, options?: BuildOptions)
You can just say the topics to watch, or there is a link to read,
Just please do not write comments like "google" "there are a lot of topics"
If you don't want to help, just pass by

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2019-09-26
@bitalikrr

I don't really understand what the & sign means.

Because Model is the object from which we get the type in the context of the type declaration, and typeof Modelhere it is the type query expression. If you don't understand why typeof can be used here, here's a great explanation , and here's a link to the language specification .
https://stackoverflow.com/a/39623422/3927447 - this means that if you have an object of type MyModelStatic, you can do this: new MyModelStatic(values, options), this is a construct signature . Pay attention to how exactly the MyModelStatic object is used in my example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question