I'm trying to learn more about typescript.
in javascript you can write a function that returns an object with properties and methods added dynamically.
For example (just an example):
function fn(val) {
var ret = {};
if (val == 1) {
ret.prop1 = "stackoverflow";
ret.fn1 = function () {
alert("hello stackoverflow");
}
}
if (val == 2) {
ret.fn2 = function () {
alert("val=2");
}
}
return ret;
}
window.onload = function () {
alert(fn(1).prop1); //alert "stackoverflow"
fn(1).fn1(); //alert "hello stackoverflow"
fn(2).fn2(); //alert "val=2"
}
In the visual studio the intellisense recognize the return value of the function and allows you to use parameters and functions.


In the first image there are "prop1" and "fn1 ()" and not "fn2 ()"
In the second image there is "fn2 ()" and not "prop1" and "fn1 ()".
you can do something similar with typescript? How?
The idea is to have one or more functions that return objects with properties and methods added dynamically based on the parameters passed to the function and visible from the visual studio intellisense.
thanks
Luca