I want typescript to reconize the dynamicly added prototyps.
Here is my code so you would know What i mean.
class Test {
name: string= "";
lastName: string = "";
}
Then I have a Method that generate props dynamicly
const public_m = (...Items: any[]) => {
try {
Items.forEach(Item => {
let keys = (
Item.tb
? Item.tb().props // if there is a db Mapped Keys takes then otherwise Object.Keys
: Object.keys(new Item())
).map(x => x.columnName || x);
// create statis "n" methods that return new objects eg Test.n()
Item["n"] = (...args: any[]) =>
new Item(...args);
// create clone Method that clone the object
Item.prototype.clone = function () {
let item = Item.n();
for (let k in this) item[k] = this[k];
return item;
};
// generate public set methods eg for name => Name() => Object(Test)
keys.forEach(x => {
let n =
x[0].toUpperCase() + x.substring(1);
if (!Item.prototype[n])
Item.prototype[n] = function (v: any) {
if (!this)
throw "this is null " + Item;
this[x] = v;
return this;
};
});
});
} catch (e) {
console.error(e, Items);
}
};
public_m(Test);
export default Test;
Lastly I am using it as fellow
let test = Test.n().Name("test").LastName("test");
The issue is that typescript wont see those methods Name() and LastName()
etc.. as those are create dynamicly