crisp-oss / email-forward-parser

🐛 Parses forwarded emails and extracts original content.
https://www.npmjs.com/package/email-forward-parser
MIT License
55 stars 23 forks source link

Add types #20

Closed nick-kang closed 1 month ago

eliottvincent commented 1 month ago

Now released as version v1.7.0: https://www.npmjs.com/package/email-forward-parser/v/1.7.0

Thanks!

eliottvincent commented 1 month ago

Hello @nick-kang

While running npx tsc on a project using this library, we have the following error:

Screen Shot 2024-10-03 at 10 42 18@2x

The code is pretty simple:

var EmailForwardParser  = require("email-forward-parser");

this.__email_forward_parser = new EmailForwardParser();

I haven't deeply checked it yet, any idea what would cause it?

nick-kang commented 1 month ago

On mobile rn, but my guess is that you'd have to add "constructor()" into the class definition.

eliottvincent commented 1 month ago

Yes we tried both constructor() and constructor() {}, no luck.

nick-kang commented 1 month ago

It likely has to do with how tsconfig is setup. The library has been compiling fine on my end. Try importing as default like here: https://github.com/ajv-validator/ajv/issues/2204

eliottvincent commented 1 month ago

Ok this makes the npx tsc succeed, but throws the following error when we run the code:

this.__email_forward_parser = new EmailForwardParser.default();
                                  ^

TypeError: EmailForwardParser.default is not a constructor

Because obviously, there is no default exported.

This is what our tsconfig.json looks like:

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "target": "es6",
    "types": ["node"],
    "moduleResolution": "NodeNext",
    "declaration": true,
    "outDir": "dist",
    "declarationMap": true
  },
  "include": ["src/**/*"]
}