Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion types/ember/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3442,7 +3442,20 @@ declare module '@ember/component/checkbox' {
declare module '@ember/component/helper' {
import Ember from 'ember';
export default class Helper extends Ember.Helper { }
export const helper: typeof Ember.Helper.helper;
/**
* In many cases, the ceremony of a full `Helper` class is not required.
* The `helper` method create pure-function helpers without instances. For
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit creates

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing @mfeckie!

These comments were copied directly from the other location in the file, which I assume were copied from here. I'm leaning towards just letting it match the docs.

As for letting users know that params[0] can be undefined, that can hopefully be inferred from the fact that params is typed as any[], and any includes undefined. Again, I took this signature directly from the source. I know of no way to type index 0 differently from the other elements of the array. CC @chriskrycho in case he does.

* example:
* ```app/helpers/format-currency.js
* import { helper } from '@ember/component/helper';
* export default helper(function(params, hash) {
* let cents = params[0];
* let currency = hash.currency;
* return `${currency}${cents * 0.01}`;
* });
* ```
*/
export function helper(helperFn: (params: any[], hash?: any) => string): any;
}

declare module '@ember/component/text-area' {
Expand Down
8 changes: 8 additions & 0 deletions types/ember/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ const CurrentUserEmailHelper = Ember.Helper.extend({
.get('email');
},
});

import { helper } from '@ember/component/helper';

function typedHelp(/*params, hash*/) {
return 'my type of help';
}

export default helper(typedHelp);