Philipp Schrader | 3d7dedc | 2024-03-16 16:27:25 -0700 | [diff] [blame^] | 1 | import { |
| 2 | ActionT, |
| 3 | ActionType, |
| 4 | {% for action in ACTIONS %} |
| 5 | {{ action }}T, |
| 6 | {% endfor %} |
| 7 | } from '@org_frc971/scouting/webserver/requests/messages/submit_2024_actions_generated'; |
| 8 | |
| 9 | export type ConcreteAction = |
| 10 | {% for action in ACTIONS %} |
| 11 | {{ action }}T {% if not loop.last %} | {% endif %} |
| 12 | {% endfor %}; |
| 13 | |
| 14 | export class ActionHelper { |
| 15 | constructor( |
| 16 | private addAction: (actionType: ActionType, action: ConcreteAction) => void |
| 17 | ){} |
| 18 | |
| 19 | {% for action in ACTIONS %} |
| 20 | // Calls `addAction` in entry.component.ts with the proper arguments. This |
| 21 | // also forces users to specify all the attributes in the `action` object. |
| 22 | public add{{ action}}(action: NonFunctionProperties<{{ action }}T>): void { |
| 23 | this.addAction(ActionType.{{ action }}, Object.assign(new {{ action }}T(), action)); |
| 24 | } |
| 25 | {% endfor %} |
| 26 | } |
| 27 | |
| 28 | type NonFunctionPropertyNames<T> = { |
| 29 | [K in keyof T]: T[K] extends Function ? never : K |
| 30 | }[keyof T]; |
| 31 | |
| 32 | type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>; |