0

I am using Visual Studio to write a ASP.NET MVC web application. I am also quite new to TypeScript, but I know C# and JavaScript so I don't have issues with the syntax.

However I am completely confused with importing/referencing .js files, namely for the two.js library:

One of the files (two.module.js) seems to be annotated with JSDoc and ends with:

export default (this || window).Two;

so I am presuming it should be importable as an ES6 module, but how does this work with TypeScript?

I tried using this:

import { Two } from "../twojs/twojs.module.js"

but I get an error (cannot find module "../twojs/twojs.module.js", presumably because it's not a .ts file.

1 Answer 1

1

You should be able to import it like this if you installed it into node_modules. The Typescript compiler will resolve the module by finding it in the node_modules folder.

Because it is a default export, you must omit the brackets here.

import Two from "two.js"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, omitting brackets fixed the problem! I think I'll have to read the TypeScript docs a bit more carefully to get a better idea of how this works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.