Skip to content

refactor: use parameter objects for all Function constructors#38

Merged
jogibear9988 merged 3 commits intomainfrom
copilot/update-functions-to-use-parameter-objects
Mar 21, 2026
Merged

refactor: use parameter objects for all Function constructors#38
jogibear9988 merged 3 commits intomainfrom
copilot/update-functions-to-use-parameter-objects

Conversation

Copy link
Contributor

Copilot AI commented Mar 21, 2026

Replace positional constructor parameters with named options objects across all classes in TiaCodegen-ts/src/Commands/Functions/, eliminating ambiguous null-heavy call sites.

Changes

  • Base classes (FunctionCall, FunctionBlockCall, SystemFunctionCall, SystemFunctionBlockCall): accept typed options objects; nullable params become optional properties
  • All leaf classes (timers, counters, triggers, arithmetic): same pattern, each with an exported *Options interface
  • AddCall/MulCall: replaced 50 repetitive positional params + assignments with optional properties and a shared addVariableInputs() helper in VariableArithmeticCall
  • External callers (InRangeCall, OutRangeCall): updated super() to match new base signatures
  • index.ts: exports all Options interfaces
  • Tests: updated to new API

Before/After

// Before — positional args, unclear what nulls mean
new CTUCall('Hallo', new Signal('bbb', SignalType.Bool), new Signal('2', SignalType.ConstantInt), new Coil(new Signal('ccc', SignalType.Bool)))
new FDBACKCall('inst', null, null, null, null, null, null, mySignal)

// After — named, only specify what you use
new CTUCall({ instanceName: 'Hallo', r: new Signal('bbb', SignalType.Bool), pv: new Signal('2', SignalType.ConstantInt), q: new Coil(new Signal('ccc', SignalType.Bool)) })
new FDBACKCall({ instanceName: 'inst', q: mySignal })

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI and others added 2 commits March 21, 2026 07:43
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 AI changed the title [WIP] Update functions to use parameter objects in constructor refactor: use parameter objects for all Function constructors Mar 21, 2026
Copilot AI requested a review from jogibear9988 March 21, 2026 07:47
@jogibear9988
Copy link
Member

@copilot
In the add call, you should add all parameters to the options object, also the optional ones. Same in the mul call.
Also optional paramters in typescript need a '?' in the options object not a '=null'
please fix all options object to use optional properties instead of '= null'

Copilot stopped work on behalf of jogibear9988 due to an error March 21, 2026 08:06
@jogibear9988 jogibear9988 marked this pull request as ready for review March 21, 2026 09:13
Copilot AI review requested due to automatic review settings March 21, 2026 09:13
@jogibear9988 jogibear9988 merged commit be0afb8 into main Mar 21, 2026
1 check failed
@jogibear9988 jogibear9988 deleted the copilot/update-functions-to-use-parameter-objects branch March 21, 2026 09:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 *Options interface.
  • Simplified AddCall/MulCall by replacing repetitive input assignments with a shared addVariableInputs() helper on VariableArithmeticCall, 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.

Comment on lines +13 to +15
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;
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants