telegraf-session-local icon indicating copy to clipboard operation
telegraf-session-local copied to clipboard

Type issue with `export = LocalSession`

Open Vico1993 opened this issue 4 years ago • 8 comments

Hey!

I used telegraf-session-local on one of my bot. Like this issue: https://github.com/RealSpeaker/telegraf-session-local/issues/117 I got an issue with export = LocalSession. My project couldn't build.

I propose this fix. That's how I import LocalSession in my project after the fix:

const LocalSession = require('telegraf-session-local')

And it worked fine.

Let me know your though!

Vico1993 avatar Jun 01 '21 01:06 Vico1993

Coverage Status

Coverage remained the same at 100.0% when pulling c53eddf558e1e117764bb5a8732dbf8e483765a8 on Vico1993:master into 19976d9346087498ee4bec97822eea8173cc9c0d on RealSpeaker:master.

coveralls avatar Jun 01 '21 01:06 coveralls

require imports are kinda deprecated in TypeScript. The way to go are ECMA Modules. TypeScript uses them natively. So with typescript you should import this way:

import LocalSession from 'telegraf-session-local';

You change changes the export from being "the" export to being one of the exports with the name LocalSession. The library itself does not export as the name and the typings should do the same:

https://github.com/RealSpeaker/telegraf-session-local/blob/19976d9346087498ee4bec97822eea8173cc9c0d/lib/session.js#L289

The best way of solving that would probably be to fully migrating to TypeScript which #119 attempts. Then the typings and the actual code are not strangely out of sync. Maybe I should try to find time for that PR again…

Do you build with or without esModuleInterop enabled? In many cases its a simple solution to just enable that.

EdJoPaTo avatar Jun 01 '21 16:06 EdJoPaTo

I did try withesModuleInterop enable and without it... same error :/

I agree that your PR #119 will make more sense than this change

Vico1993 avatar Jul 22 '21 01:07 Vico1993

Hey! How to solve this problem?

An export assignment cannot be used in a module with other exported elements.

34 export = LocalSession

TEHbKA-dev avatar Sep 09 '21 06:09 TEHbKA-dev

@TemaSM any updates?

qWici avatar Nov 18 '21 17:11 qWici

@qWici see https://github.com/RealSpeaker/telegraf-session-local/pull/119#issuecomment-882582018

Personally I switched from telegraf to grammY and plan on using grammy-file-storage which has simpler code and compatibility with both Deno and Node.js.

EdJoPaTo avatar Nov 18 '21 18:11 EdJoPaTo

still not merged?

kekemeke avatar Dec 06 '21 11:12 kekemeke

@kekemeke see both of my messages. Firstly this PR is technically wrong as the typings differ from the sources. Secondly you might want to consider switching to grammY.

grammY has a way better way of handling sessions compared to Telegraf which throws out a lot of complexity while allowing for more demanding use cases.

Somewhere on my TODO list is the migration of telegraf-session-local data to ~~grammy-file-storage data~~ any grammY storage adapter. When I have done that I want to write a small guide on how to do that for other people with the same problem. If you write a script or so to do that feel free to share!

EdJoPaTo avatar Dec 06 '21 12:12 EdJoPaTo