To use the _.values
function from the Underscore library in TypeScript, you should first install the Underscore library if you don't already have it installed by using the following command:
index.ts23 chars2 lines
Then, import the values
function from the underscore
module like this:
index.ts37 chars2 lines
Now you can use the values
function to get the values of an object as an array. The function takes an object as an argument and returns an array of its values.
index.ts90 chars4 lines
You can also use the values
function with TypeScript generics to specify the type of the values in the returned array. For example, if you have an object with values of type string
, you can use the values
function with a generic type argument like this:
index.ts122 chars4 lines
This ensures that the type of the values in the returned array is string
.
gistlibby LogSnag