gx0r/connect-session-knex

Cannot use v2.1.1 in TypeScript

Morgul opened this issue ยท 7 comments

It seems #89 actually breaks usage in TypeScript projects:

$ tsc && DEBUG=true node ./dist/server.js
node_modules/connect-session-knex/typings/index.d.ts:19:5 - error TS2666: Exports and export assignments are not permitted in module augmentations.

19     export = initFunction;
       ~~~~~~


Found 1 error.

To be honest, I don't think the change was correct; it appears TypeScript only allows esm module syntax inside of module blocks.

Edit: It appears, if you use require, it works, but now all TypeScript projects are forced to use require syntax. The original author could have solved their problem with:

import sessionModule from 'connect-session-knex';
const session = sessionModule.default;

IMHO, that's preferable to disallowing import session from 'connect-session-knex';.

I also have this problem. I had to fork the package and revert the change made in #89

Additionally I think #95 also broke things as I had to revert that to get rid of

node_modules/connect-session-knex/typings/index.d.ts:8:14 - error TS2709: Cannot use namespace 'Knex' as a type.

Is it possible to update the type definitions? cf. https://github.com/knex/knex/blob/master/UPGRADING.md#upgrading-to-version-0950

I also have:

node_modules/connect-session-knex/typings/index.d.ts:20:5 - error TS2666: Exports and export assignments are not permitted in module augmentations.

20     export = initFunction;

@gx0r ?

It's still broken:

node_modules/connect-session-knex/typings/index.d.ts:8:14 - error TS2709: Cannot use namespace 'Knex' as a type.

8       knex?: Knex;
               ~~~~

node_modules/connect-session-knex/typings/index.d.ts:20:5 - error TS2666: Exports and export assignments are not permitted in module augmentations.

20     export = initFunction;
       ~~~~~~

FWIW here's my working patch (using node.js with ESM ("type": "module") and esModuleInterop: true):

diff --git a/typings/index.d.ts b/typings/index.d.ts
index cc2df0e156521f0ca56b52b4fc9cf3b087221a5b..ed92de0672e11428f03db5e217d9cf9edb534d86 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -15,6 +15,8 @@ declare module 'connect-session-knex' {
     interface StoreFactory {
         new (configs?: ConfigType): Store;
     }
-}
 
-export default function initFunction(session: typeof expressSession): StoreFactory;
+    function initFunction(session: typeof expressSession): StoreFactory;
+
+    export = initFunction
+}

+1, the above patch fixes the issue for me.

gx0r commented

Thank you, pushed that fix ๐Ÿ™

gx0r commented

and published 4.0.1