mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
90 lines
2.7 KiB
Diff
90 lines
2.7 KiB
Diff
--- old.jsDeclarationsFunctionLikeClasses2(target=es2015).errors.txt
|
|
+++ new.jsDeclarationsFunctionLikeClasses2(target=es2015).errors.txt
|
|
@@= skipped -0, +0 lines =@@
|
|
-<no content>
|
|
+referencer.js(3,23): error TS2350: Only a void function can be called with the 'new' keyword.
|
|
+source.js(13,16): error TS2749: 'Vec' refers to a value, but is being used as a type here. Did you mean 'typeof Vec'?
|
|
+source.js(40,16): error TS2350: Only a void function can be called with the 'new' keyword.
|
|
+
|
|
+
|
|
+==== source.js (2 errors) ====
|
|
+ /**
|
|
+ * @param {number} len
|
|
+ */
|
|
+ export function Vec(len) {
|
|
+ /**
|
|
+ * @type {number[]}
|
|
+ */
|
|
+ this.storage = new Array(len);
|
|
+ }
|
|
+
|
|
+ Vec.prototype = {
|
|
+ /**
|
|
+ * @param {Vec} other
|
|
+ ~~~
|
|
+!!! error TS2749: 'Vec' refers to a value, but is being used as a type here. Did you mean 'typeof Vec'?
|
|
+ */
|
|
+ dot(other) {
|
|
+ if (other.storage.length !== this.storage.length) {
|
|
+ throw new Error(`Dot product only applicable for vectors of equal length`);
|
|
+ }
|
|
+ let sum = 0;
|
|
+ for (let i = 0; i < this.storage.length; i++) {
|
|
+ sum += (this.storage[i] * other.storage[i]);
|
|
+ }
|
|
+ return sum;
|
|
+ },
|
|
+ magnitude() {
|
|
+ let sum = 0;
|
|
+ for (let i = 0; i < this.storage.length; i++) {
|
|
+ sum += (this.storage[i] ** 2);
|
|
+ }
|
|
+ return Math.sqrt(sum);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * @param {number} x
|
|
+ * @param {number} y
|
|
+ */
|
|
+ export function Point2D(x, y) {
|
|
+ if (!(this instanceof Point2D)) {
|
|
+ return new Point2D(x, y);
|
|
+ ~~~~~~~~~~~~~~~~~
|
|
+!!! error TS2350: Only a void function can be called with the 'new' keyword.
|
|
+ }
|
|
+ Vec.call(this, 2);
|
|
+ this.x = x;
|
|
+ this.y = y;
|
|
+ }
|
|
+
|
|
+ Point2D.prototype = {
|
|
+ __proto__: Vec,
|
|
+ get x() {
|
|
+ return this.storage[0];
|
|
+ },
|
|
+ /**
|
|
+ * @param {number} x
|
|
+ */
|
|
+ set x(x) {
|
|
+ this.storage[0] = x;
|
|
+ },
|
|
+ get y() {
|
|
+ return this.storage[1];
|
|
+ },
|
|
+ /**
|
|
+ * @param {number} y
|
|
+ */
|
|
+ set y(y) {
|
|
+ this.storage[1] = y;
|
|
+ }
|
|
+ };
|
|
+
|
|
+==== referencer.js (1 errors) ====
|
|
+ import {Point2D} from "./source";
|
|
+
|
|
+ export const origin = new Point2D(0, 0);
|
|
+ ~~~~~~~~~~~~~~~~~
|
|
+!!! error TS2350: Only a void function can be called with the 'new' keyword.
|
|
+ // export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this
|
|
+
|