Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript typing problem - numbro.d.ts should not use "export default" #403

Closed
ntamas opened this issue Jan 21, 2019 · 5 comments
Closed

TypeScript typing problem - numbro.d.ts should not use "export default" #403

ntamas opened this issue Jan 21, 2019 · 5 comments

Comments

@ntamas
Copy link
Contributor

@ntamas ntamas commented Jan 21, 2019

The TypeScript typing file for numbro has recently been changed as follows between versions 2.1.0 and 2.1.1:

-export = numbro;
+export default numbro;

(Related issue: #352, related PR: #363)

This causes problems if Numbro is being used in a TypeScript project where tsconfig.json specifies module: "commonjs" and target: "es5". Since the typing file declares that numbro has a default export, TS only accepts the following syntax to import the entire module:

import numbro from "numbro";

numbro(123);

However, this transpiles down to the following in ES5:

var numbro_1 = require("numbro");

numbro_1.default(123);

which is incorrect because the JS code of numbro does not have a property named default - the module exports the entire numbro function as the module-level export instead. I believe that the typing file should revert to export = numbro to reflect this, or the module itself should include exports.default = numbro to provide a default export.

@zuzusik

This comment has been minimized.

Copy link

@zuzusik zuzusik commented Feb 26, 2019

yeah, this affects us too

@szoper

This comment has been minimized.

Copy link

@szoper szoper commented Jul 9, 2019

Is there any workaround for this?

@ntamas

This comment has been minimized.

Copy link
Contributor Author

@ntamas ntamas commented Oct 15, 2019

@BenjaminVanRyseghem this is still an issue, as exemplified by #435; the changes provided in #430 does not address the original problem reported here.

@BenjaminVanRyseghem

This comment has been minimized.

Copy link
Owner

@BenjaminVanRyseghem BenjaminVanRyseghem commented Mar 18, 2020

in numbro 2.2.0

@isidorosp

This comment has been minimized.

Copy link

@isidorosp isidorosp commented Mar 29, 2020

I'm still getting this in 2.2.0 with the following tsconfig:
"module": "commonjs", "target": "es2019",
the following import statement:
import numbro from 'numbro';
and the following usage:
numbro(value).format({ thousandSeparated: true, mantissa: 2 });
the following error occurs:
numbro_1.default is not a function TypeError: numbro_1.default is not a function

EDIT:
@BenjaminVanRyseghem
Sorry for the @ but just checking if you had a chance to see the above as the issue was closed when I commented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.