refactor: use parameter objects for all Function constructors#38
Conversation
Refactored all function classes in TiaCodegen-ts/src/Commands/Functions/ to use parameter objects instead of positional parameters. Nullable parameters are now optional properties in the options objects. Also exported the Options interfaces from index.ts and updated tests and callers (InRangeCall, OutRangeCall) to use the new constructor signatures. Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnetprojects/TiaCodeGen/sessions/7d8e1d80-543d-42c2-8cb4-0fa6305ad65c
…variable inputs Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnetprojects/TiaCodeGen/sessions/7d8e1d80-543d-42c2-8cb4-0fa6305ad65c
|
@copilot |
There was a problem hiding this comment.
Pull request overview
This PR refactors the TiaCodegen-ts/src/Commands/Functions/ API to consistently use named, typed “options objects” for constructors instead of positional parameters, reducing ambiguous null-heavy call sites and improving call-site readability.
Changes:
- Updated function base classes (
FunctionCall,FunctionBlockCall,SystemFunctionCall,SystemFunctionBlockCall) to accept typed options objects (with nullable parameters becoming optional properties). - Updated all leaf function classes (timers, counters, triggers, arithmetic) to the same constructor pattern, each with an exported
*Optionsinterface. - Simplified
AddCall/MulCallby replacing repetitive input assignments with a sharedaddVariableInputs()helper onVariableArithmeticCall, and updated tests/call sites accordingly.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| TiaCodegen-ts/src/Commands/Functions/Base/FunctionCall.ts | Introduces FunctionCallOptions and switches base constructor to options object. |
| TiaCodegen-ts/src/Commands/Functions/Base/FunctionBlockCall.ts | Introduces FunctionBlockCallOptions and adapts super() usage to new base signature. |
| TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionCall.ts | Converts constructor to accept SystemFunctionCallOptions and forwards to FunctionCall. |
| TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionBlockCall.ts | Converts constructor to accept SystemFunctionBlockCallOptions and forwards to FunctionBlockCall. |
| TiaCodegen-ts/src/Commands/Functions/*.ts | Updates all function implementations to accept options objects and pass the new base options into super(). |
| TiaCodegen-ts/src/Commands/Functions/Arithmetic/*.ts | Refactors arithmetic calls to options objects; adds addVariableInputs() helper to reduce duplication. |
| TiaCodegen-ts/src/Commands/Comparisons/InRangeCall.ts | Updates super() call to new SystemFunctionCall options signature. |
| TiaCodegen-ts/src/Commands/Comparisons/OutRangeCall.ts | Updates super() call to new SystemFunctionCall options signature. |
| TiaCodegen-ts/src/index.ts | Re-exports the new *Options interfaces as type exports alongside their classes. |
| TiaCodegen-ts/tests/SampleTests.test.ts | Updates test call sites to the new constructor options-object APIs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| protected addVariableInputs(options: object, startIndex: number, endIndex: number): void { | ||
| for (let i = startIndex; i <= endIndex; i++) { | ||
| const value = ((options as Record<string, unknown>)[`in${i}`] as IOperationOrSignal | null | undefined) ?? null; |
There was a problem hiding this comment.
addVariableInputs takes options: object and then casts to Record<string, unknown> to index dynamic inN fields. This drops type-safety for callers/overrides and makes it easy to accidentally pass non-IOperationOrSignal values without a compile-time error. Consider typing options as a Record<string, IOperationOrSignal | null | undefined> (or a generic constrained record) so the indexing doesn’t require unknown casts.
| protected addVariableInputs(options: object, startIndex: number, endIndex: number): void { | |
| for (let i = startIndex; i <= endIndex; i++) { | |
| const value = ((options as Record<string, unknown>)[`in${i}`] as IOperationOrSignal | null | undefined) ?? null; | |
| protected addVariableInputs( | |
| options: Record<string, IOperationOrSignal | null | undefined>, | |
| startIndex: number, | |
| endIndex: number | |
| ): void { | |
| for (let i = startIndex; i <= endIndex; i++) { | |
| const value = options[`in${i}`] ?? null; |
Replace positional constructor parameters with named options objects across all classes in
TiaCodegen-ts/src/Commands/Functions/, eliminating ambiguous null-heavy call sites.Changes
FunctionCall,FunctionBlockCall,SystemFunctionCall,SystemFunctionBlockCall): accept typed options objects; nullable params become optional properties*OptionsinterfaceAddCall/MulCall: replaced 50 repetitive positional params + assignments with optional properties and a sharedaddVariableInputs()helper inVariableArithmeticCallInRangeCall,OutRangeCall): updatedsuper()to match new base signaturesindex.ts: exports all Options interfacesBefore/After
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.