Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/node-opcua-convert-nodeset-to-javascript/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Changelog

## [Unreleased]

### Fixed

#### Fix #1: Inherited member type compatibility

**Problem:**
When a derived class overrides a member without adding new sub-members, the generator used the raw TypeDefinition type instead of the specialized type from the base class.

**Example:**
```typescript
// Base class defines specialized type:
interface UAIJoiningSystemAsset_identification
extends Omit<UAMachineryItemIdentification, "manufacturer"|"serialNumber"> { ... }

// BEFORE (wrong): Generator used generic type
identification: UAMachineryItemIdentification;

// AFTER (correct): Generator uses specialized type from base class
identification: UAIJoiningSystemAsset_identification;
```

This caused TS2430 errors in some NodeSets (e.g., LADS):
```
error TS2430: Interface 'UAMultiSensorFunction_Base' incorrectly extends interface 'UABaseSensorFunction_Base'.
```

**Solution:**
If the base class has a specialized type for a member, use that type to maintain compatibility in the inheritance chain.

---

#### Fix #2: Correct type arguments for inherited generic types

**Problem:**
When `childType` was inherited from the base class (via Fix #1), the type arguments (suffix) were still computed based on the TypeDefinition, not the inherited type.

**Example:**
```typescript
// Base class: (with Fix #1)
currentValue: UADiscreteItem<any, any>; // 2 type args (generic)

// TypeDefinition (TwoStateDiscreteType) has dataType=Boolean, so only 1 param

// BEFORE (wrong):
currentValue: UADiscreteItem<boolean>; // 1 arg - TS2314 error!

// AFTER (correct):
currentValue: UADiscreteItem<boolean, DataType.Boolean>; // 2 args, specific ✓
```

**Solution:**
When inheriting `childType` from the base class, recalculate the type arguments based on the base type's generic parameters, combined with the current node's specific dataType.

---

### Affected NodeSets

The fixes correct type generation in the following existing NodeSets:
- node-opcua-nodeset-ua (3 files)
- node-opcua-nodeset-ijt-base (14 files)
- node-opcua-nodeset-scales-v-2 (7 files)
- node-opcua-nodeset-glass-flat (2 files)
- node-opcua-nodeset-machine-tool (1 file)
- node-opcua-nodeset-padim (1 file)
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,9 @@ export async function extractClassMemberDef(
assert(innerClass);
assert(childBase);
} else {
// may not expose definition but we may want to used the augment typescript class defined in the definition
// we don't need to create an inner class ...
// xxxx NOT HERE childType = sameMemberInBaseClass ? sameMemberInBaseClass?.childType : childType;
if (sameMemberInBaseClass && sameMemberInBaseClass.childType.name !== childType.name) {
childType = sameMemberInBaseClass.childType;
}
assert(!innerClass);
assert(!childBase);
}
Expand Down Expand Up @@ -647,6 +647,29 @@ export async function extractClassMemberDef(
...classMember,
...extra
};

const baseParentDef2 = parentDef.superType && parentDef.baseClassDef;
if (baseParentDef2) {
const sameMemberInBase = baseParentDef2.members.find(
(m) => m.browseName.toString() === browseName.toString()
);
if (sameMemberInBase && sameMemberInBase.childType.name === classMember.childType.name
&& sameMemberInBase.childType.name !== typeDefinition.browseName.name?.toString()) {
// childType was inherited from base (e.g., UADiscreteItem instead of UATwoStateDiscrete)
// Recalculate suffix based on base class's classDef
if (sameMemberInBase.classDef && classMember.dataType !== undefined) {
const baseTypeHasUnspecifiedDataType =
sameMemberInBase.classDef.dataType === DataType.Null ||
sameMemberInBase.classDef.dataType === DataType.Variant;

if (baseTypeHasUnspecifiedDataType && classMember.dataType !== DataType.Null && classMember.dataType !== DataType.Variant) {
// Base type is generic (2 params), current has specific dataType
// Generate: <specificType, DataType.SpecificType>
classMember.suffixInstantiate = `<${classMember.jtype}, DataType.${DataType[classMember.dataType]}>`;
}
}
}
}
}

return classMember;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { UAObject, UAMethod, UAProperty } from "node-opcua-address-space-base"
import { DataType } from "node-opcua-variant"
import { LocalizedText } from "node-opcua-data-model"
import { UInt16, UAString } from "node-opcua-basic-types"
import { UAFiniteStateVariable } from "node-opcua-nodeset-ua/dist/ua_finite_state_variable"
import { UAStateVariable } from "node-opcua-nodeset-ua/dist/ua_state_variable"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAFolder } from "node-opcua-nodeset-ua/dist/ua_folder"
import { UALockingServices } from "node-opcua-nodeset-di/dist/ua_locking_services"
import { UAProductionStateMachine } from "./ua_production_state_machine"
import { UAInitializingSubStateMachine } from "./ua_initializing_sub_state_machine"
import { UAInstruction } from "./ua_instruction"
export interface UAProductionJob_state extends Omit<UAProductionStateMachine, "currentState"> { // Object
currentState: UAFiniteStateVariable<LocalizedText>;
currentState: UAStateVariable<LocalizedText>;
initializedState: UAInitializingSubStateMachine;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LocalizedText } from "node-opcua-data-model"
import { UAFiniteStateMachine, UAFiniteStateMachine_Base } from "node-opcua-nodeset-ua/dist/ua_finite_state_machine"
import { UAState } from "node-opcua-nodeset-ua/dist/ua_state"
import { UATransition } from "node-opcua-nodeset-ua/dist/ua_transition"
import { UAFiniteStateVariable } from "node-opcua-nodeset-ua/dist/ua_finite_state_variable"
import { UAStateVariable } from "node-opcua-nodeset-ua/dist/ua_state_variable"
import { UAInitialState } from "node-opcua-nodeset-ua/dist/ua_initial_state"
import { UAInitializingSubStateMachine } from "./ua_initializing_sub_state_machine"
/**
Expand All @@ -17,7 +17,7 @@ import { UAInitializingSubStateMachine } from "./ua_initializing_sub_state_machi
export interface UAProductionStateMachine_Base extends UAFiniteStateMachine_Base {
aborted: UAState;
abortedToInitializing: UATransition;
currentState: UAFiniteStateVariable<LocalizedText>;
currentState: UAStateVariable<LocalizedText>;
ended: UAState;
endedToInitializing: UATransition;
initializing: UAInitialState;
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { UAString } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
export interface UAIAccessory_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
* type
Expand Down Expand Up @@ -32,7 +31,7 @@ export interface UAIAccessory_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { Int64, Byte, UAString } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
import { UAJoiningDataVariable } from "./ua_joining_data_variable"
export interface UAIBattery_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
Expand Down Expand Up @@ -71,7 +70,7 @@ export interface UAIBattery_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_cable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { Byte } from "node-opcua-basic-types"
import { UAMultiStateDiscrete } from "node-opcua-nodeset-ua/dist/ua_multi_state_discrete"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
import { UAJoiningDataVariable } from "./ua_joining_data_variable"
export interface UAICable_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
Expand Down Expand Up @@ -36,7 +35,7 @@ export interface UAICable_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { Byte } from "node-opcua-basic-types"
import { UAMultiStateDiscrete } from "node-opcua-nodeset-ua/dist/ua_multi_state_discrete"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
export interface UAIController_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
* type
Expand All @@ -30,7 +29,7 @@ export interface UAIController_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_feeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { DataType } from "node-opcua-variant"
import { Byte, UAString } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMultiStateDiscrete } from "node-opcua-nodeset-ua/dist/ua_multi_state_discrete"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
import { UAJoiningDataVariable } from "./ua_joining_data_variable"
export interface UAIFeeder_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
Expand Down Expand Up @@ -50,7 +49,7 @@ export interface UAIFeeder_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { UInt64, UAString } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
export interface UAIMemoryDevice_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
* storageCapacity
Expand Down Expand Up @@ -44,7 +43,7 @@ export interface UAIMemoryDevice_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { UAString } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
import { UAJoiningDataVariable } from "./ua_joining_data_variable"
export interface UAIPowerSupply_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
Expand Down Expand Up @@ -50,7 +49,7 @@ export interface UAIPowerSupply_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { DataType } from "node-opcua-variant"
import { Int64, Byte } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMultiStateDiscrete } from "node-opcua-nodeset-ua/dist/ua_multi_state_discrete"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
export interface UAISensor_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
* measuredValue
Expand Down Expand Up @@ -44,7 +43,7 @@ export interface UAISensor_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_servo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { Int16 } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
export interface UAIServo_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
* nodeNumber
Expand Down Expand Up @@ -32,7 +31,7 @@ export interface UAIServo_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opcua-nodeset-ijt-base/source/ua_i_software.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ----- this file has been automatically generated - do not edit
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
/**
* | | |
* |----------------|------------------------------------------------------------|
Expand All @@ -20,7 +19,7 @@ export interface UAISoftware_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
}
export interface UAISoftware extends Omit<UAIJoiningSystemAsset, "identification">, UAISoftware_Base {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { DataType } from "node-opcua-variant"
import { UAString } from "node-opcua-basic-types"
import { UABaseDataVariable } from "node-opcua-nodeset-ua/dist/ua_base_data_variable"
import { UAMachineryItemIdentification } from "node-opcua-nodeset-machinery/dist/ua_machinery_item_identification"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base } from "./ua_i_joining_system_asset"
import { UAIJoiningSystemAsset_parameters, UAIJoiningSystemAsset, UAIJoiningSystemAsset_Base, UAIJoiningSystemAsset_identification } from "./ua_i_joining_system_asset"
export interface UAISubComponent_parameters extends UAIJoiningSystemAsset_parameters { // Object
/**
* type
Expand Down Expand Up @@ -32,7 +31,7 @@ export interface UAISubComponent_Base extends UAIJoiningSystemAsset_Base {
* it with MachineIdentificationType or
* MachineryComponentIdentificationType.
*/
identification: UAMachineryItemIdentification;
identification: UAIJoiningSystemAsset_identification;
/**
* parameters
* The Parameters Object is an instance of
Expand Down
Loading