route-recognizer icon indicating copy to clipboard operation
route-recognizer copied to clipboard

TypeScript declaration is wrong in CommonJS

Open tomdale opened this issue 9 years ago • 6 comments

The .d.ts file exports a default class, which makes TypeScript look for a .default property on the exports object in CommonJS. However, in CommonJS environments, the exports object is set to the class itself. This makes it unusable in Node.js/TypeScript projects.

tomdale avatar Apr 21 '17 22:04 tomdale

You can fix by telling rollup to force default export but this will make people need require("x").default but if you don't do this it will happen as soon as someone adds a named export

krisselden avatar Apr 22 '17 19:04 krisselden

I think if we want interop it is best to avoid module.exports assignment altogether

krisselden avatar Apr 22 '17 19:04 krisselden

@krisselden I agree. Personally, I don't mind having to do .default in Node, but that may be a minority opinion.

tomdale avatar Apr 29 '17 16:04 tomdale

Is there a change this being merged in for a new version?

jvanoostveen avatar Aug 18 '18 12:08 jvanoostveen

I was really hoping to use this lib in one of my project, because I was sure I could share code between frontend and backend, but I guess I was wrong :(

atheros avatar Apr 02 '19 12:04 atheros

FWIW this is now solved by typescript with the allowSyntheticDefaultImports option, otherwise the typedef matches the module build

calebboyd avatar Apr 29 '20 18:04 calebboyd