Skip to content Skip to sidebar Skip to footer

How To Call JavaScript From TypeScript?

I have a javascript file that I want to call from typescript. I fixed one import problem and modified the base function to be recognized in tsc, however, I'm still facing an issue

Solution 1:

Here's an answer why you're unable to use fat arrow syntax if you want to access prototype: https://teamtreehouse.com/community/does-arrow-function-syntax-works-for-prototype

Here's two additional explanations about this with fat arrow syntax:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#No_separate_this

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Use_of_prototype_property

As a resolution you need to define it with normal function declaration:

const XmlRpcRequest = function(url, method) { ... }

Alternatively, you could use class:

class XmlRpcRequest {
  constructor(url, method) {
    ...
  }
}

Post a Comment for "How To Call JavaScript From TypeScript?"