Skip to content

FAQ: diffence of import and require #334

@malleus35

Description

@malleus35

Hello, I want to use seneca with Typescript.
So, I import seneca node package to use import statement.
I run tutorial code to have little change. Like this.

import Seneca from "seneca";
const seneca = Seneca();

seneca.add({ role: "math", cmd: "sum" }, function (
  msg: any,
  respond: Function
) {
  var sum = msg.left + msg.right;
  respond(null, { answer: sum });
});

seneca.add({ role: "math", cmd: "product" }, function (
  msg: any,
  respond: Function
) {
  var product = msg.left * msg.right;
  respond(null, { answer: product });
});

seneca
  .act({ role: "math", cmd: "sum", left: 1, right: 2 }, console.log)
  .act({ role: "math", cmd: "product", left: 3, right: 4 }, console.log); // This line has Error
/*
*  Property 'act' does not exist on type 'void'.ts(2339)
*/

Could you tell me how can i use ES6 module system?
If this problem can't solve without CommonJS module system, then i use require statement.
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions