M
M
Michael2017-06-04 01:25:38
Node.js
Michael, 2017-06-04 01:25:38

Why is typescript behaving so strangely?

I'm trying to make friends here ts and node.js, but I ran into two problems:
1) I can not connect the module.
Main.ts and redisApi.ts are in the same folder. In redisApi.ts I wrote a class:

class RedisApi {
constructor() {
}

someMethod() {

}

}

module.exports = RedisApi;

In main.ts I write:
import RedisApi = require('./redisApi');
const redisApi = new RedisApi(redisClient, ['one', 'two', 'three', 'four']);

And I get an error: Cannot use 'new' with an expression whose type lacks a call or construct signature.
If you do not take out the class in a separate module, then everything works. Where is the mistake?
2) Why does TS require an async function to always return a Promise? It seemed to me that the async keyword was needed in order to indicate that inside the function, await would be used before the function that returned the Promise. And the async function itself can return anything. Is not it so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Coder321, 2017-06-04
@mak_ufo

1) Why are you doing module.exports inside the class?
2) See here, the first paragraph will explain everything

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question