Home > database >  Return string from function typescript
Return string from function typescript

Time:10-22

I am having issues returning a string instead of a function in an object value. Currently an arrow function returns an array of objects, and one of those needs to conditionally change a value based on the value passed in. Here's the code:

const requestOptions = () => [
{
     id: 3,
     label: (object: Object) => `${activeStatus(object)}`,
     value: 'toggleActiveStatus',
}] 

The activeStatus method returns a string, but really struggling to get label to be assigned a string instead of type (validationRule: ValidationRule) => string. requestOptions gets invoked to return the options as prop for a component.

I have tried a number of variations of

label: (object: Object) => string = () => {

and invoking the function as an IIFE.

Any ideas on how I could get it to return the string itself, not the function? Thanks in advance!

CodePudding user response:

If you want label to be a string, then you can simply drop the anonymous function:

const requestOptions = () => [
{
     id: 3,
     label: `${activeStatus(object)}`,
     value: 'toggleActiveStatus',
}] 
  • Related