given following code:
class ConnectionOptions
{
host: string = "localhost";
port: number = 5672;
username: string = "guest";
password: string = "guest";
}
class ConnectorClass
{
options: ConnectionOptions = new ConnectionOptions();
SetOptions(options: ConnectionOptions)
{
console.log(options);
this.options = options;
}
}
// Adopt singleton pattern
var Connector = (function () {
var instance : ConnectorClass;
function createInstance() {
return new ConnectorClass();
}
return {
I: function () : ConnectorClass {
if (!instance) {
instance = createInstance();
}
return instance;
}
};
})();
// TestApp
Connector.I().SetOptions({ 'host': "192.168.17.5" });
In the last line there is following typescript error:
index.ts:50:26 - error TS2345: Argument of type '{ host: string; }' is not assignable to parameter of type 'ConnectionOptions'.
Type '{ host: string; }' is missing the following properties from type 'ConnectionOptions': port, username, password
50 Connector.I().SetOptions({ 'host': "192.168.17.5" });
I understand why the error is thrown: TS is expecting 4 properties but I only want to set 1 of them, isnt this possible in Typescript?