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

Cannot use v2.1.1 in TypeScript #97

Closed
Morgul opened this issue Feb 27, 2022 · 7 comments
Closed

Cannot use v2.1.1 in TypeScript #97

Morgul opened this issue Feb 27, 2022 · 7 comments

Comments

@Morgul
Copy link
Contributor

Morgul commented Feb 27, 2022

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';.

@public
Copy link

public commented Jun 8, 2022

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.

@xegulon
Copy link

xegulon commented Sep 30, 2022

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 ?

@Morgul
Copy link
Contributor Author

Morgul commented Dec 26, 2022

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;
       ~~~~~~

@mifi
Copy link

mifi commented Nov 18, 2023

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

@imskyyc
Copy link

imskyyc commented May 29, 2024

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

@gx0r
Copy link
Owner

gx0r commented May 29, 2024

Thank you, pushed that fix 🙏

@gx0r
Copy link
Owner

gx0r commented May 29, 2024

and published 4.0.1

@gx0r gx0r closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants