Categories
TypeScript Answers

How to use Object.values with TypeScript?

Spread the love

Sometimes, we want to use Object.values with TypeScript.

In this article, we’ll look at how to use Object.values with TypeScript.

How to use Object.values with TypeScript?

To use Object.values with TypeScript, we should set the compilerOptions.lib option to include 'es2017' or a later version of JavaScript.

For instance, we write

{
  //...
  "compilerOptions": {
    "lib": ["es2017", "dom"]
  }
  //...
}

in tsconfig.json to include 'es2017' in the compilerOptions.lib array so that the TypeScript compiler is aware that features in ES2017, including Object.values are available.

Conclusion

To use Object.values with TypeScript, we should set the compilerOptions.lib option to include 'es2017' or a later version of JavaScript.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *