TypeScript hasOwnProperty equivalent

If obj is a TypeScript object (instance of a class), is there a way to perform the same operation?

Your JavaScript is valid TypeScript (more). So you can use the same code as it is.

Here is an example:

class Foo{
    foo = 123
}

const dict = new Foo();
const obj = {} as Foo;

for (let key in dict) {
  if (obj.hasOwnProperty(key)) {
    obj[key] = dict[key];
  }
}

Note: I would recommend Object.keys(obj).forEach(k=> even for JavaScript, but that is not the question you are asking here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)