Type a function based on its argument value.

I have a function that takes an object and a boolean (default to false). It will return an array of object with key id only if parameter bool of the function set to true.
const helpMeTypeThis = (obj: MyObj, bool = false)
: {id?: string | undefinded, [key: string]: any }[] => {
return obj.map(...)
}

helpMeTypeThis(obj) // => { [key: string]: any }
helpMeTypeThis(obj, false) // => { [key: string]: any }
helpMeTypeThis(obj, true) // => { id: string, [key: string]: any }
const helpMeTypeThis = (obj: MyObj, bool = false)
: {id?: string | undefinded, [key: string]: any }[] => {
return obj.map(...)
}

helpMeTypeThis(obj) // => { [key: string]: any }
helpMeTypeThis(obj, false) // => { [key: string]: any }
helpMeTypeThis(obj, true) // => { id: string, [key: string]: any }
1 Reply
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server