Generics using using table values #2181
Answered
by
carsakiller
GiuseppeIII
asked this question in
Q&A
-
I currently have a function that looks like this:
Would it be possible to use generics so that the return table could be of type table<return_field_values, any>? |
Beta Was this translation helpful? Give feedback.
Answered by
carsakiller
Jul 3, 2023
Replies: 1 comment
-
Unfortunately, generic classes are not yet supported. However, once they are, your code would likely look like this: ---@class get_params<T>
---@field endpoint Endpoint db table you want to get
---@field where Where | Where[] what fields to query table on
---@field return_fields table<T, any> | "ALL" what fields to return
---@field on_empty? OnEmpty what to do if no data is returned, defaults to NOTHING
---@generic T
---@param get_params get_params<T>
---@return table<T, any>?
function Connector.get(get_params) end |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
GiuseppeIII
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, generic classes are not yet supported. However, once they are, your code would likely look like this: