A
A
alex4answ2020-10-17 18:20:34
typescript
alex4answ, 2020-10-17 18:20:34

What is the difference between using generics and specifying a literal?

Good evening, there is such a design:

import type { Model, ModelCtor } from 'sequelize';

const isExistsValidator = (model: ModelCtor<Model>, field: string) => { ... }

ModelCtor:
export type ModelCtor<M extends Model> = typeof Model & { new(): M };


But for some reason, if you use a generalization, then the type does not converge:
import type { Model, ModelCtor } from 'sequelize';

const isExistsValidator = <M extends Model>(model: ModelCtor<M>, field: string) => { ... }

Immediately in the body of the function there are errors that I don’t really understand, but that’s not the point.

model - class, descendant of Model
What is the difference between variants with and without generalization?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question