0

So, in Node.js to export primary and "secondary" functions I would do:

module.exports = (amount) => {
  return amount
}

module.exports.calc = (amount) => {
  return amount * amount
}

module.exports.stringify = (amount) => {
  return String(amount)
}

And then call it from other files like so:

const amountix = require('./amountix')

amountix(20) // 20
amountix.calc(20) // 400
amountix.stringify(20) // "20"

But now I need to convert the this module from Node.js to TypeScript. I tried the following:

export default (amount: number): number => {
  return amount;
}

export function calc(amount: number): number {
  return amount * amount;
}

export function stringify(amount: number): string {
  return String(amount);
}

import * as amountix from "./amountix.ts"

amountix(20) // ERROR: This expression is not callable.
amountix.calc(20) // 400
amountix.stringify(20) // "20"

But it gives me error when I call the "primary" function.

How do I do it the right way?

1 Answer 1

1
import * as amountix from './amountix';

// call the default method
amountix.default(20);

Or

import amountix, { calc, stringify } from './amountix';

amountix(20);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.