I have the following code snippets:
File router-data.ts#L46
...
const fd = FroniusMeter.getInstance(req.query.address ? req.query.address : 1);
....
The method getInstance() is defined in file fronius-meter.ts#L51
public static getInstance (id: string): FroniusMeter {
if (id.startsWith('/dev')) {
debug.info('...');
}
let rv = ModbusDevice.getInstance(id);
if (!rv) {
rv = ModbusDevice.instances.find( (d) => (d instanceof FroniusMeter) && (d.address === +id) );
}
return rv instanceof FroniusMeter ? rv : null;
}
The sources are transpiled without warning or error (tsconfig.json), but executing throws an exception TypeError: id.startsWith is not a function.
The reason is clear, the call of getInstance() uses a number as parameter, but the method is written for a string as parameter. Therefore id.startsWith(... throws an error.
My question, why did typescript transpilation not print out some warning or error?