Reputation: 1522
this is a typescript supported simple create-react-app project, and i use VS code
i downloaded geometry.d.ts
and geometry.js
(which renamed from geometry.mjs) into the project
then i try to import it like import * as g from "../../shared/geometry";
funny thing is, ts-check said i have type 2 g
s to get inside the g
namespace
but after compiled and run in browser, g.g
is undefined
what happed here? how to get rid of the second g
?
Upvotes: 0
Views: 129
Reputation: 1522
OK,finally,
I placed the .d.ts filne to a separate folder
I added a reference comment /// <reference path="../../types/geometry.d.ts" />
in the head of geometry.js file
in the end of it, change the code like this
// exports.Curve = Curve;
// exports.Ellipse = Ellipse;
// exports.Line = Line;
// exports.Path = Path;
// exports.Point = Point;
// exports.Polyline = Polyline;
// exports.Rect = Rect;
// exports.bezier = bezier;
// exports.ellipse = ellipse;
// exports.line = line;
// exports.normalizeAngle = normalizeAngle;
// exports.point = point;
// exports.random = random;
// exports.rect = rect;
// exports.scale = scale;
// exports.snapToGrid = snapToGrid;
// exports.toDeg = toDeg;
// exports.toRad = toRad;
export {
Curve,
Ellipse,
Line,
Path,
Point,
Polyline,
Rect,
bezier,
ellipse,
line,
normalizeAngle,
point,
random,
rect,
scale,
snapToGrid,
toDeg,
toRad
};
then import g like import * as g from "../shared/geometry";
everthing looks fine now
Upvotes: 1