Suppose Object
is something that is importable and we currently use Object.getOwnPropertyNames
. Could we do:
import {getOwnPropertyNames} from 'Object';
TypeScript uses the ES2015 concept of modules (more here), but Object
isn't a module, so you can't do what you've shown, but you can use destructuring assignment instead:
const { getOwnPropertyNames } = Object;
...which is the same as:
const getOwnPropertyNames = Object.getOwnPropertyNames;
For any method that doesn't rely on a particular this
value (and the ones on Object
don't), you could use the result on its own:
const obj = {a: 1, b: 2};
const { getOwnPropertyNames } = Object;
console.log(getOwnPropertyNames(obj));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With