Not exactly what you're asking for, but the end result works:
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'));
EDIT I read your answer to my comment. I think the simpler way to achieve your goal is to use default parameters like such:
function foo(text: string, snapshot = false): string{
if(snapshot){
return 'snapshot';
}
return text;
}
console.debug(foo('test'));
console.debug(foo('test', true));
Now your solution has the advantage that you can see at the call site that you are requesting a bypass or a snapshot clearly because of the additional function names. You can achieve a similar result in typescript by replacing the arguments of foo with an interface with optional properties. In other languages, we would call this technique 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}));