Daniel
Daniel

Reputation: 11

Syntax for using math.js in typescript file

I am writing an office 365 addin using typescript. I am trying to use functions from math.js. In my home.html head tag, I have the line:

 <script src="https://unpkg.com/mathjs/lib/browser/math.js"></script>

I test that I can use mathjs in this file through:

<script type="text/javascript">
    console.log(math.sqrt(-4).toString()) // 2i
</script>

which outputs 2i to the console as expected. I have another typescript file where I want to use math.erf. Here, it does not recognize math.

I have tried changing math.erf to erf but then it does not recognize erf. I have tried:

import { erf } from 'mathjs'

as the first line of the file. This breaks the file so functions in the file are not recognized elsewhere.

I have tried:

const math = require('mathjs');

inside my function. I get a runtime error that require is not defined. I have added:

  "dependencies": {"mathjs": "13.2.0"},

to my package.json file. I am not sure if this is necessary.

Upvotes: 0

Views: 69

Answers (0)

Related Questions