简体   繁体   中英

Creating Javascript object from Typescript

I am trying to create a javascript object from Typescript.

This is the Javasript object I am trying to create:https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.js

In the javascript sample, you just create the object like this:

this.engine = new Chess();

How do I do this in Typescript?

I imported the object like this (I downloaded the file and added it to my project):

import * as Chess from './../chess.js';

However, if I try to create a Chess object I get a build error:

const engine = new Chess();

Error says: Cannot use 'new' with an expression whose type lacks a call or construct signature.

Thanks everyone for your responses. I did a lot of digging into the different methods and I found this just might work.

npm install --save chess.js

This creates a node module for chess.js .

From there I can create the class object like this:

import * as Chess from "./../../node_modules/chess.js";

var chess = new Chess();

I have not tested it in depth, but I was able to call functions in the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM