0

How to import non typescript library using ES6 import statement

import {observable, action, computed, transaction} from "mobx";

and

import lib from "somelib"

1 Answer 1

2

There are a few ways depending on how the code was modularized. With well structure libraries with ES6-style module declarations, like lodash, you can use ES6 import statements as expected despite them not using TypeScript:

import * from "lodash" as _;

With other libraries, you can just require the library as you would normally and assign it to the import:

import lib = require("somelib");
Sign up to request clarification or add additional context in comments.

1 Comment

Second option worked for me, just added a declare for require function also declare function require(name: string): any; Thanks faraz !!!

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.