TypeScript代码
import ModbusRTU from 'modbus-serial';
var modbus = new ModbusRTU();
modbus.connectTCP("192.168.1.5", { port: 502 });
modbus.setID(1);
setInterval(function() {
modbus.writeRegister(2048, 2);
}, 100);
转换为
"use strict";
exports.__esModule = true;
var modbus_serial_1 = require("modbus-serial");
var modbus = new modbus_serial_1["default"](); // <-- HERE
modbus.connectTCP("192.168.1.5", { port: 502 });
modbus.setID(1);
setInterval(function () {
modbus.writeRegister(2048, 2);
}, 100);
但是,该代码仅在类实例化时不使用["default"]
时才有效-
"use strict";
exports.__esModule = true;
var modbus_serial_1 = require("modbus-serial");
var modbus = new modbus_serial_1(); // <-- HERE
modbus.connectTCP("192.168.1.5", { port: 502 });
modbus.setID(1);
setInterval(function () {
modbus.writeRegister(2048, 2);
}, 500);
如何告诉编译器点头将其添加到代码中?