im try to create a global prototype with a custom function.
I need this:
console.log({'active':1, 'profile':1}._state())
{'active':true,'profile':1,'state':'root'}
I try this:
global.ts
declare global {
interface Object {
_state(): Object;
}
}
Object.prototype._state = function (): Object {
if (this.active === 1) {
this.active = true;
}
if (this.profile === 1) {
this.state = 'root';
}
return this;
};
export {};
When I try to use, fail with this error:
TS2339: Property '_state()' does not exist on type {'active':1, 'profile':1}
And in my class say component.ts
import '. /global.ts';
@Injectable()
export class AppState{
constructor(){
console.log({'active':1, 'profile':1}._state());
}
}
TS2345: Argument of type 'AppState' is not assignable to parameter of type 'Object'