David Rodrigues
David Rodrigues

Reputation: 12532

Export class static method

Is possible I export a class static method on TypeScript to NodeJs? Example:

class Help {
    static show() { ... }
}

export = Help.show;

It returns it:

class.Help.ts(5,19): error TS1005: ';' expected.

Upvotes: 1

Views: 2433

Answers (2)

basarat
basarat

Reputation: 275819

An alternative solution:

class Help {
    static show() {  }
}

var show = Help.show;
export = show;

The limitation is by design. Stuff after export = needs to be an identifier. E.g. the following will not compile either:

var foo = {show:()=>null}
export = foo.show;

Upvotes: 5

David Rodrigues
David Rodrigues

Reputation: 12532

I found a good solution for me:

class Help {
    static show() { ... }
}

export function show() { return Help.show.apply(this, arguments); }

But I think that is possible exists a native solution. Right?

Upvotes: 0

Related Questions