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
I was wondering if it was possible to use some sort of function to generate a set of dynamic arguments on an abstract class decorated with "@ArgsType"
Take the code below for example:
exportfunctionWhereArguments(type: string){constproperties=getConnection().getMetadata(type).ownColumns.map(column=>({type: column.type,name: column.propertyName}))conststrings=properties.filter(property=>property.type===String||property.type==='text')constbooleans=properties.filter(property=>property.type===Boolean||property.type==='bool'||property.type==='boolean')constbaseFilters=properties.filter(property=>!strings.includes(property)&&!booleans.includes(property)).map(({ name })=>[`${name}`,`${name}_gt`,`${name}_lt`,`${name}_gte`,`${name}_lte`,`${name}_not`])conststringFilters=strings.map(({ name })=>[name,`${name}_gt`,`${name}_lt`,`${name}_gte`,`${name}_lte`,`${name}_not`,`${name}_contains`,`${name}_not_contains`,`${name}_starts_with`,`${name}_not_starts_with`,`${name}_ends_with`,`${name}_not_ends_with`])constbooleanFilters=booleans.map(({ name })=>name)constfilters=[].concat.apply([],[...stringFilters, ...booleanFilters, ...baseFilters])
@ArgsTypeclassAbstract{// is it possible to define properties on this class, based on the filters array?}returnAbstract}
My question, is it possible to apply properties to this class based on the 'filters' array so the end result would be like:
Technically it's possible (call the decorator function manually, like in transpilled JS code) but you will loose type safety in your code as TypeScript is not capable of handling dynamic property values.
Maybe in your case, you should just use a more static-type friendly way for declaring arguments? There was a discussion about it: #134 (comment)
I was wondering if it was possible to use some sort of function to generate a set of dynamic arguments on an abstract class decorated with "@ArgsType"
Take the code below for example:
My question, is it possible to apply properties to this class based on the 'filters' array so the end result would be like:
I'm not sure if this is possible, but it would save me a lot of time than having to define each of those for each of my entities/object types
The text was updated successfully, but these errors were encountered: