To use the propertyOf
function from the Underscore library in Typescript, you can follow the steps below:
Install the underscore library by running the following command in your terminal:
index.ts23 chars2 lines
Next, import the propertyOf
function from the underscore library in your Typescript file:
index.ts41 chars2 lines
Now, you can create a function that takes an object and a property name as inputs and returns the value of that property from the object using propertyOf
:
index.ts112 chars5 lines
The getProperty
function can now be used to get the value of properties from objects as follows:
index.ts163 chars4 lines
Note: the any
type is used for the obj
input parameter in the getProperty
function as propertyOf
works with any object type. However, it is recommended to use a more specific type for the obj
parameter if possible.
gistlibby LogSnag