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
// -------- BASE CLASSES ---------------classModel{fields!: ModelFields;options!: ModelOptions<this>;}// ------- BUG ------------------------classUserextendsModel{fields={a: FieldTypes.BOOL}// V - βοΈ HERE IS THE BUG!!!! Why? and how to solve it?options: ModelOptions<this>={indexes: [{unique: true,fields: ['a']// <- β This works as expected though}]}}// ------------ TYPES ----------------enumFieldTypes{CHAR='CHAR',BOOL='BOOL',INT='INT'}typeModelIndex<MextendsModel>={unique: true;fields: (keyofM["fields"])[];}typeOrderingOfModelOptions<MextendsModel>=keyofM["fields"]|keyof{[FinkeyofM["fields"]asFextendsstring ? `-${F}` : never] : 1}typeModelOptions<MextendsModel>={indexes?: ModelIndex<M>[];ordering?: OrderingOfModelOptions<M>[];}typeModelFields={[field: string]: FieldTypes}
π Actual behavior
Although i'm passing the correct arguments, it just don't work. It just don't work because the type ModelIndexes is an object, which is really strange to me.
I've tried changing the name of the fields to something else like attributes but no success, so it does not seem that the problem is the name.
I saw that on ModelIndexes it looks like M and Model are having an automatic intersection like M & Model, but it needs some further investigation.
I've tried doing conditional like M extends Model ? (keyof M["fields"])[] : never; but no success, the condition actually works but the problem then will be something like Type '"a"[]' is not assignable to type 'this extends Model ? (keyof this["fields"])[] : never
π Expected behavior
in this example indexes: { union: true, fields: ['a']} should work because 'a' is defined in the User model fields object and indexes: { union: true, fields: ['b']} should not work because 'b' it's not defined inside of fields in User model
The expected behavior is to just work as 3.3.3 worked, so it accepts a union of all of the keys of the object not as all of the above versions works.
The text was updated successfully, but these errors were encountered:
Your property fields has the type { a: FieldTypes }, but your generic type ModelOptions<> requires the type argument to extend Model. But the type of this is { fields: { a: FieldTypes } }, and it does not extend Model (which is { fields: ModelFields; options: ModelOptions<this> }).
When you type your property fields correctly it works:
Bug Report
π Search Terms
this, assertion error, generics, type inference, automatic intersection
π Version & Regression Information
Looks like it's above version 3.3.3333
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Although i'm passing the correct arguments, it just don't work. It just don't work because the type ModelIndexes is an object, which is really strange to me.
fields
to something else likeattributes
but no success, so it does not seem that the problem is the name.ModelIndexes
it looks likeM
andModel
are having an automatic intersection likeM & Model
, but it needs some further investigation.M extends Model ? (keyof M["fields"])[] : never;
but no success, the condition actually works but the problem then will be something likeType '"a"[]' is not assignable to type 'this extends Model ? (keyof this["fields"])[] : never
π Expected behavior
in this example
indexes: { union: true, fields: ['a']}
should work because 'a' is defined in the User modelfields
object andindexes: { union: true, fields: ['b']}
should not work because 'b' it's not defined inside offields
in User modelThe expected behavior is to just work as 3.3.3 worked, so it accepts a union of all of the keys of the object not as all of the above versions works.
The text was updated successfully, but these errors were encountered: