Add a new test to the Clusterfactorytest.ts like
it("creates clusterserver with a feature and handlers", () => {
const fullCluster = ClusterServer(
TestExtensibleCluster.with("Extended"),
{
attr1: 1,
attr2: 2,
},
{
cmd1: ({ attributes: { attr1, attr2 }, session, endpoint}) => {
if (attr1 == undefined || attr2 == undefined || session === undefined || endpoint === undefined) throw new Error("Missing attribute");
},
cmd2: ({ request: { cmdField1 }, attributes: { attr1, attr2 }, session, endpoint}) => {
if (cmdField1 === undefined || attr1 == undefined || attr2 == undefined || session === undefined || endpoint === undefined) throw new Error("Missing attribute");
return { cmdRet1: 5 };
},
getAttr1: ({ attributes: { attr1, attr2 }, session, endpoint}) => {
if (attr1 == undefined || attr2 == undefined || session === undefined || endpoint === undefined) throw new Error("Missing attribute");
return 5;
}
},
{
ev1: true,
ev2: true,
}
);
})
including one adkjustment:
const ELEMENTS2 = {
attributes: {
attr2: Attribute(4, TlvUInt8)
},
commands: {
cmd2: Command(5, TlvObject({ cmdField1: TlvField(1, TlvUInt16)}), 5, TlvObject({ cmdRet1: TlvField(1, TlvUInt16)}))
},
events: {
ev2: Event(6, EventPriority.Debug, TlvNoArguments)
}
}
All the attributes and request options are all considered "any" which is wrong. Interestingly enough the return type is interfered correctly.
After tracking it down I ended in the fact that the method extendCluster in CLusterfactory does an "inplace" upgrade for the operative data of the clusters but the typing extension do not seem to work correctly.
Also in BLE branch (in matter-node.js/-examples/DevcieNode.ts we have a Wifi Networking cluster. here it is the same but the typing error also points to something more as it seems:
So adjust to like
and you get
src/examples/DeviceNode.ts:180:21 - error TS2322: Type '({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }: { request: { ssid: any; breadcrumb: any; }; attributes: { lastNetworkingStatus: any; }; endpoint: any; }) => Promise<{ networkingStatus: NetworkCommissioningStatus; wiFiScanResults: { ...; }[]; }>' is not assignable to type '(args: { request: any; attributes: AttributeServers<{ maxNetworks: FixedAttribute<number, any>; networks: Attribute<TypeFromFields<{ networkId: FieldType<Uint8Array>; connected: FieldType<...>; }>[], any>; interfaceEnabled: WritableAttribute<...>; lastNetworkingStatus: Attribute<...>; lastNetworkId: Attribute<...>; ...'.
Types of parameters '__0' and 'args' are incompatible.
Type '{ request: any; attributes: AttributeServers<{ maxNetworks: FixedAttribute<number, any>; networks: Attribute<TypeFromFields<{ networkId: FieldType<Uint8Array>; connected: FieldType<boolean>; }>[], any>; interfaceEnabled: WritableAttribute<...>; lastNetworkingStatus: Attribute<...>; lastNetworkId: Attribute<...>; las...' is not assignable to type '{ request: { ssid: any; breadcrumb: any; }; attributes: { lastNetworkingStatus: any; }; endpoint: any; }'.
Types of property 'attributes' are incompatible.
Property 'lastNetworkingStatus' is missing in type 'AttributeServers<{ maxNetworks: FixedAttribute<number, any>; networks: Attribute<TypeFromFields<{ networkId: FieldType<Uint8Array>; connected: FieldType<boolean>; }>[], any>; interfaceEnabled: WritableAttribute<...>; lastNetworkingStatus: Attribute<...>; lastNetworkId: Attribute<...>; lastConnectErrorValue: Attribut...' but required in type '{ lastNetworkingStatus: any; }'.
180 scanNetworks: async ({
~~~~~~~~~~~~
This brings me to https://github.com/project-chip/matter.js/blob/main/packages/matter.js/src/cluster/server/ClusterServer.ts#L41 where an arg is in and the error "Types of parameters '__0' and 'args' are incompatible." could match to that ?!
So something is lost on the road ...
It seems to work in general for base clusters because we have sevewral such clusters workig including access, so my assumptions went the "Extend" direction that it comes from there.
For me it seems that after Extend the linked Type "CommandHandler" can not infer the types of the command and so ends in the "never" case ... becuse it works with empty method.