Access table field dynamically by an index - help with types
Hello! I'm further extending the DAO from https://discord.com/channels/1043890932593987624/1147439990683488268 , and currently I'm trying to implement custom ordering. I've already written the code which works, and the only thing I'm missing is type-compliance - accessing table column directly by an index gives me this TS error:
The code which errors:
The question is - how can I tell typescript, that this is valid? I'm fine with any type casting solutions, I just don't know how can I take this further.
4 Replies
Casting it to
AnyColumns
works:
I also changed the FieldOrder
field
to keyof directly from TTable instead of InferSelectModel. This makes sure that TS2322 is shown if field name doesn't exists in the table. The drawback is, that it also shows attributes, such as _
, and methods (getSQL()
)Alright, this can be further narrowed down with TS Omit helper:
tada ✨