1

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?

Tuizi
  • 1,643
  • 4
  • 22
  • 34

1 Answers1

0

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.

Fenton
  • 241,084
  • 71
  • 387
  • 401
  • Ok thx, is it correct? `declare var AudioContext: window.AudioContext;` and next use `this.context = new AudioContext()` ? – Tuizi Aug 30 '13 at 19:55
  • 1
    `AudioContext = webkitAudioContext || msAudioContext || mozAudioContext` – Tuizi Aug 30 '13 at 20:14