I am looking to execute something dependent on the type of connection it is. But have not found a way.
const onSaveHandler = async (connection: Connection) => {
if (connection is serial) { // do serial task }
if (connection is ethernet) { //do ethernet task }
}
All connections have ID, NAME, TYPE,....
export interface Connection {
[CONNECTION_ID_KEY]: number;
[CONNECTION_NAME_KEY]: string;
[CONNECTION_TYPE_ID_KEY]: number;
[CONNECTION_TYPE_NAME_KEY]?: string;
[CONNECTION_COMM_INTERVAL_KEY]: number;
}
Two classes extend:
export interface SerialConnection extends Connection {
[COM_PORT_KEY]: number;
[BAUD_RATE_KEY]: number;
[DATA_BITS_KEY]: number;
[STOP_BITS_KEY]: number;
[PARITY_KEY]: number;
}
export interface EthernetConnection extends Connection {
[IP_ADDRESS_KEY]: string;
[PORT_NUMBER_KEY]: number;
}
To see what I am trying to achieve https://codesandbox.io/s/mbuqb