telegraf-session-local
telegraf-session-local copied to clipboard
Type issue with `export = LocalSession`
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!
Coverage remained the same at 100.0% when pulling c53eddf558e1e117764bb5a8732dbf8e483765a8 on Vico1993:master into 19976d9346087498ee4bec97822eea8173cc9c0d on RealSpeaker:master.
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.
I did try withesModuleInterop enable and without it... same error :/
I agree that your PR #119 will make more sense than this change
Hey! How to solve this problem?
An export assignment cannot be used in a module with other exported elements.
34 export = LocalSession
@TemaSM any updates?
@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.
still not merged?
@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!