How to import library with TypeScript Playground

0 votes

TypeScript Playground does not seem to work the right way with this import:

import * as _ from "underscore";

until you try to use it, like:

const equalResult = _.isEqual('ABC', '123');

Then, it generates the error:

[ERR]: Executed JavaScript Failed:
[ERR]: Cannot use import statement outside a module

The playground seems to understand the library because it gives JSDoc, so I'm thinking that this can work, but how?

Jun 13, 2022 in TypeSript by Logan
• 2,140 points
3,038 views

1 answer to this question.

0 votes

TypeScript Playground isn't a fully fledged sandbox solution. It's merely meant as a simple type explorer that doesn't need dependencies.

For your use case I would recommend using CodeSandbox instead. It comes with a whole bunch of TypeScript templates to choose from when creating a sandbox. TypeScript Playground also has an export menu where you can open your code in CodeSandbox directly.

CodeSandbox export

The UI is based off of VS Code, so if you're used to that you will feel just at home.

answered Jun 13, 2022 by Nina
• 3,060 points

Related Questions In TypeSript

0 votes
1 answer

How to use useState hook in React with TypeScript correctly?

Without any initial argument, the type of email and setEmail will ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
1,921 views
0 votes
1 answer

How to use useState hook in React with typescript correctly?

You can set a string type for it Explicit way: const ...READ MORE

answered Aug 3, 2022 in TypeSript by Abhinaya
• 1,160 points
4,230 views
0 votes
1 answer

How to create ES6 Map in Typescript

Refer this as an example this.configs = new ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
838 views
0 votes
1 answer

How to declare and initialize a Dictionary in Typescript

Apparently this doesn't work when passing the ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
6,496 views
0 votes
1 answer

How to read local csv file in JavaScript/TypeScript?

Here is how to use the readAsBinaryString() from the FileReader API ...READ MORE

answered Jun 9, 2022 in TypeSript by Nina
• 3,060 points
2,696 views
0 votes
1 answer

Cannot access web3 object with typescript and ethereum

You still need to instantiate it first. ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,370 points
2,888 views
0 votes
1 answer

Display details of importer

Yes, you can perform the same by ...READ MORE

answered Mar 15, 2019 in Python by SDeb
• 13,300 points
760 views
0 votes
1 answer

Can't import tkinter

You can Try this code to import ...READ MORE

answered May 21, 2019 in Python by SDeb
• 13,300 points
1,651 views
0 votes
1 answer

How to use moment.js library in angular 2 typescript app?

REFERENCE: https://momentjs.com/docs/#/use-it/typescript/ You can install this by using: npm install ...READ MORE

answered Jun 1, 2022 in TypeSript by Nina
• 3,060 points
1,662 views
0 votes
1 answer

how to use spread syntax and new Set() with TypeScript

The ... operator should work on anything ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
490 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP