Typescript and javascript class

1.9k views Asked by At

How can I instanciate javascript class in type script?

For exemple:

class LiveAudioFreq {
    context;

    constructor(){
        context = new window.AudioContext();
    }
}

Give me the error:

error TS2094: The property 'AudioContext' does not exist on value of type 'Window'.

And refuse to compile, how can I use javascript methods in my ts file?

1

There are 1 answers

2
Fenton On

In the constructor, use:

this.context = ...

Rather than just

context = ...

Also, where have you defined AudioContext? It is likely that this won't be in the standard library until it is implemented everywhere, so you may need to create an ambient declaration.