Although it may not be exactly what you had in mind, the following code accomplishes the desired result:
class MyClass {
public foo: MyChildClass = new MyChildClass();
}
class MyChildClass {
public bar(text: string): string{
return text;
}
}
const obj = new MyClass();
console.log(obj.foo.bar('thing'));
UPDATE After reading your response to my previous comment, I believe a simpler way to achieve your objective is by using default parameters as shown below:
function foo(text: string, snapshot = false): string{
if(snapshot){
return 'snapshot';
}
return text;
}
console.debug(foo('test'));
console.debug(foo('test', true));
With this approach, you can clearly see at the point of function call whether you are requesting a bypass or a snapshot due to the additional function names. A similar outcome can be achieved in TypeScript by substituting the arguments of `foo` with an interface containing optional properties. In other programming languages, this technique is often referred to as named parameters:
interface iFooArgs{
text: string;
bypass?: boolean;
snapshot?: boolean;
}
function foo(args: iFooArgs): string {
if(args.bypass){
return 'bypass';
}
if(args.snapshot){
return 'snapshot';
}
return args.text;
}
console.debug(foo({text: 'test'}));
console.debug(foo({text: 'bypass?', bypass: true}));
console.debug(foo({text: 'snapshot?', snapshot: true}));