1

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.

2 Answers 2

5

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome! It's better than my own method. Thanks!
Thanks. Note you only need ` .apply` if you want to preserve this in a function. This is not required for static methods as this will not point to some instance. this preservation is need for member methods and typescript has good ways : youtube.com/watch?v=tvocUcbCupA
0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.