0

Here is my function:

const payout = (asset: ILPAsset, type: string)
    => type === 'daily' ? asset.lastPayout : asset.historical;

And where I'm using it:

@bind
private mapDailyAssets(payoutType: string, payout: payoutFunc, assets: ILPAsset[], currency: string) {
  return assets.map((asset) => (
    <div className={b('table-row')()} key={asset.symbol}>
      <div>{asset.symbol}</div>
      <div className={b('asset-value')()}>{formatMoney(payout(asset, payoutType), currency)}</div>
    </div>
  ));
}

I'm getting errors when trying to set an interface for type payoutFunc:

interface payoutFunc: (asset: ILPAsset, type: string) => string;

But also getting this error:

invoke an expression whose type lacks a call signature

enter image description here

1 Answer 1

1

Your syntax for declaring a function signature interface is not quite right. It should look like this:

interface payoutFunc { 
  (asset: ILPAsset, type: string): string;
}

Or you could use a type alias:

type payoutFunc = (asset: ILPAsset, type: string) => string;

In either case you can use this type as a prop somewhere else:

interface MyProps {
  foo: string;
  bar: number;
  payout: payoutFunc;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This was exactly what I needed, other questions on stack just covered the function itself, wasn't looking for the Typescript function type syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.