In extensions.js
, I have the following code:
Array.prototype.shuffle = function() {
for (let i = this.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this[i], this[j]] = [this[j], this[i]];
}
}
In test.js
, I import the file, and then try to use the new prototype function:
import 'extensions.js';
function() {
var arr = []; // or new Array()
arr.shuffle();
}
Unfortunately, the import doesn't seem to augment the Array type.
[ts] Property 'shuffle' does not exist on type 'any[]'. any