Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

Import AMD/requirejs Javascript file into Typescript

I have a library: js and d.ts files. How can I import them in es6 typescript file?

Javascript file

define("Calculator", ["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Calculator = /** @class */ (function () {
        function Calculator() {
        }
        Calculator.prototype.calc = function (a) {
            return a + 1;
        };
        return Calculator;
    }());
    exports.default = Calculator;
});

d.ts file

declare module "Calculator" {
    export default class Calculator {
        calc(a: number): number;
    }
}

Typescript file with import:

import calculator = require('../libs/calculator');

Error says File '.../libs/calculator.d.ts' is not a module

question from:https://stackoverflow.com/questions/65852919/import-amd-requirejs-javascript-file-into-typescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...