0

I need to work with a legacy library that's plain old javascript, but which I have renamed with a .ts extension so I can gradually refactor it. This is mostly working, but the code does one thing that Typescript doesn't like:

function TestUtil() {}

TestUtil._startTime;

and the Typescript compiler is complaining that Error TS2339 (TS) Property '_startTime' does not exist on type 'typeof TestUtil'.

I cannot find any syntax that will let me indicate that TestUtil should be treated like any, so that I don't get this kind of compilation error. How can I get around this

2 Answers 2

1

If you want TestUtil to be defined as any (which is probably not recommended), you can do this as such:

const TestUtil:any = function() {}
Sign up to request clarification or add additional context in comments.

1 Comment

I'd like to give it strong typings, but for now I just want to use it as is, but without the compilation errors.
1

Shouldn't the _startTime var be declared inside the function? The function TestUtil has no var _startTime declared inside of it

Maybe convert it to a class and set _startTime as an static attribute?

class TestUtil() {
    static _startTime: any;
}

1 Comment

Yes it should. There's a lot of weird syntax and a fair number of bugs. Indeed the point of converting this to Typescript is to get the compiler's help in finding and fixing them.

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.