connect-session-knex icon indicating copy to clipboard operation
connect-session-knex copied to clipboard

Cannot use v2.1.1 in TypeScript

Open Morgul opened this issue 3 years ago • 4 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';.

Morgul avatar Feb 27 '22 19:02 Morgul

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.

public avatar Jun 08 '22 10:06 public

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 ?

xegulon avatar Sep 30 '22 16:09 xegulon

Pushed a fix, I believe (?)

gx0r avatar Oct 29 '22 18:10 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;
       ~~~~~~

Morgul avatar Dec 26 '22 17:12 Morgul

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
+}

mifi avatar Nov 18 '23 12:11 mifi