You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the underlying types of the findAll method, I was expecting TypeScript to complain about inexistent key names in the where clause but it doesn't:
const records = await Model.findAll({ where: { inexistentField: 'value' } }); // TS does not check for the existence of inexistentField
Hovering over the where attribute, my ide shows: where: WhereOptions<any> | undefined, confirming that TS has no clue about the model we're operating on.
But shouldn't the findAll method be able to infer the type of the model it was called on?
public static findAll<M extends Model>( this: ModelStatic<M>, options?: FindOptions<Attributes<M>>): Promise<M[]>;
Explicitly passing the model class as a generic doesn't help either:
const records = await Model.findAll<ModelClass>({ where: { inexistentField: 'value' } }); // still no ts complaint
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Looking at the underlying types of the findAll method, I was expecting TypeScript to complain about inexistent key names in the where clause but it doesn't:
const records = await Model.findAll({ where: { inexistentField: 'value' } });
// TS does not check for the existence of inexistentField
Hovering over the
where
attribute, my ide shows:where: WhereOptions<any> | undefined
, confirming that TS has no clue about the model we're operating on.But shouldn't the findAll method be able to infer the type of the model it was called on?
public static findAll<M extends Model>( this: ModelStatic<M>, options?: FindOptions<Attributes<M>>): Promise<M[]>;
Explicitly passing the model class as a generic doesn't help either:
const records = await Model.findAll<ModelClass>({ where: { inexistentField: 'value' } }); // still no ts complaint
Beta Was this translation helpful? Give feedback.
All reactions