Typescript: Calling a "method" of another class
There are several problems with your code.
- Typescript is case sensitive. So "calcSomething" and "calcSomeThing" are two different methods.
- The only way to access cals methods and properties is through "this" keyword: this.foo
- To define class property use private/protected/public modifier. Or no modifier at all (that will be the same as public). So no things like "var foo" in the class body.
Taking this into account the fixed code would look like this:
export class Foo
{
calcSomeThing(parameter:number): number
{
//Stuff
}
}
class Bar
{
private foo:Foo = new Foo();
calcOtherThing(parameter: number): number
{
return this.foo.calcSomeThing(parameter)
}
}
calcSomeThing
is a non-static method/function. Create an instance of Foo
to be able to call it:
let foo:Foo = new Foo();
let result:number = foo.calcSomeThing( parameter );
Never use var
in Typescript - let
is your friend.