'What is the expected error code returned if the IoTHub device is disabled while still connected?
I would like to know what is the expected error code returned if the IoTHub device is disabled while still connected in the IoTHub. I tested it with the scenario below:
Scenario A:
- Device is connected to iothub.
- Disable the device in azure iot explorer.
- Device was disconnected.
Actual result: Error code received was IOTHUB_CLIENT_CONNECTION_NO_NETWORK
I expect that the error code should be IOTHUB_CLIENT_CONNECTION_DEVICE_DISABLED
Scenario B:
- Disable the device first in iothub.
- Device will attempt the connection. Actual result: error code received was IOTHUB_CLIENT_CONNECTION_DEVICE_DISABLED
Scenario B is expected. How about scenario A?
Thank you very much for your support!
Solution 1:[1]
Foo["value"] is the same as writing string | number. It has no relation to the parameter o.
As a workaround, you can use this pattern:
export function foo<Foo extends Any>(o: Foo): Foo["value"] {
switch (o.type) {
case "string":
let v1 = o.value;
v1 = "42";
return v1;
case "number":
let v2 = o.value;
v2 = "42"; // Type 'string' is not assignable to type 'number'.(2322)
return v2;
}
}
The idea is that let v2 = o.value pins v2 to have type number due to type narrowing. Then you get the error. Unfortunately you need a variable for each case, if you use let v = o.value before the switch v will have type string | number.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
