tock icon indicating copy to clipboard operation
tock copied to clipboard

TypeError: tocktimer_1.Tock is not a constructor

Open malorus opened this issue 8 years ago • 5 comments

Hi, using this library, I run into the following error:

Tock is not a constructor

I'm using it in conjunction with nodejs and Typescript:

import { Tock } from 'tocktimer';

export class MyClass {
time = new Tock();

...
}

why does the error occur? Any idea?

malorus avatar Sep 29 '17 21:09 malorus

try removing the curly braces from the import

ydaniv avatar Sep 30 '17 09:09 ydaniv

I think ydaniv is right. I should probably add this to the readme.

mrchimp avatar Sep 30 '17 11:09 mrchimp

Thanks guys, but unfortunately it didn't work. I got the error:

tocktimer_1.default is not a constructor

But I found a way that worked for me:

import * as Tock from 'tocktimer';

This is the only way that worked.

malorus avatar Sep 30 '17 11:09 malorus

how about just

import 'tock';

?

mrchimp avatar Sep 30 '17 18:09 mrchimp

no, this won't work. Typescript does not recognise the class. Even when declaring

declare var Tock: any;

so that VSCode does not show any errors and I then create a new object

new Tock()

leads to the error:

ReferenceError: Tock is not defined

malorus avatar Oct 01 '17 11:10 malorus