# Helper and returning the resolved value of a promise

**URL:** <https://discuss.emberjs.com/t/helper-and-returning-the-resolved-value-of-a-promise/10975>\
**Category:** Uncategorized\
**Created:** [June 20, 2016, 10:50am UTC](https://discuss.emberjs.com/t/helper-and-returning-the-resolved-value-of-a-promise/10975 "2016-06-20T10:50:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fguillen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/fguillen/32/11714_2.png) [@fguillen](https://discuss.emberjs.com/u/fguillen)\
**Post date:** [June 20, 2016, 10:50am UTC](https://discuss.emberjs.com/t/helper-and-returning-the-resolved-value-of-a-promise/10975/1 "2016-06-20T10:50:03Z")

</div>

I have this Helper:

```
export function myHelper(params) {
  let myObject = params[0];
  return myObject.myMethod();
}

```

But this is sending this error to console:

```
my-helper.js:8 Uncaught TypeError: myObject.myMethod is not a function

```

I think it is because `myObject` is an unresolved promise.

I have tried this:

```
return myObject.then((myObject) => { return myObject.myMethod(); });

```

But it is not working.

How can I return the resolved value of a promise?

---

<div class="post-metadata">

**Author:** ![Diahron\_Grismore](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@Diahron\_Grismore](https://discuss.emberjs.com/u/Diahron_Grismore)\
**Post date:** [June 21, 2016, 1:35am UTC](https://discuss.emberjs.com/t/helper-and-returning-the-resolved-value-of-a-promise/10975/2 "2016-06-21T01:35:35Z")

</div>

You need to remove the comments: (params \*/, hash \*/) should be (params)… Here’s the link to documentation for helpers: [Writing Helpers - Templates - Ember Guides](https://guides.emberjs.com/v2.2.0/templates/writing-helpers/) . good luck

---

<div class="post-metadata">

**Author:** ![fguillen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/fguillen/32/11714_2.png) [@fguillen](https://discuss.emberjs.com/u/fguillen)\
**Post date:** [June 21, 2016, 7:17am UTC](https://discuss.emberjs.com/t/helper-and-returning-the-resolved-value-of-a-promise/10975/3 "2016-06-21T07:17:06Z")

</div>

I have removed the comment in my code example. Don’t think this is relevant though 🙂

---

<div class="post-metadata">

**Author:** ![Motocarota](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/motocarota/32/12309_2.png) [@Motocarota](https://discuss.emberjs.com/u/Motocarota)\
**Post date:** [June 21, 2016, 8:56am UTC](https://discuss.emberjs.com/t/helper-and-returning-the-resolved-value-of-a-promise/10975/4 "2016-06-21T08:56:34Z")

</div>

> [@fguillen](#):
>
> How can I return the resolved value of a promise?

To return the resolved value of a promise, you need to use the then(), like you did:

`return promise.then( value => { return value } )`

I see a naming collision on “myObject” that is assigned both on the params[0] value (the promise) and the argument of the then call (the promised value) you should rename that

```
export function myHelper(params) {

    var promise = params[0]
    return promise.then( ( myObject ) => {
        return myObject.myMethod()
    } )
}

```

but in case that is not your problem, try checking with debugger/console.log the first/most stupid things that could go wrong:

- is params an array?
- is params[0] a promise?
- is myObject an object?
- is myObject.myMethod a function?
- does myObject.myMethod return something? etc.

that’s what I do when I am in these situation, based on my desperation level:

```
export function myHelper(params) {

    console.log( "params: ", typeof( params ) ) 
    var promise = params[0]
    console.log( "promise: ", typeof( promise ) ) 
    debugger;

    return promise.then( ( myObject ) => {

        console.log( "myObject: ", typeof( myObject ) ) 
        console.log( "myMethod: ", typeof( myObject.myMethod ) ) 
        let value = myObject.myMethod()
        console.log( "value: ", typeof( myObject.myMethod( ) ) ) 
        debugger;

        return value
    } ).catch( error => { 
        console.log( "got error:", error )
        debugger ;
    } )
}

```

and so on… hope that helped 🙂
