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

TypeScript: Cannot find module 'diary' or its corresponding type declarations #11

Closed
abeforgit opened this issue Jun 18, 2021 · 7 comments

Comments

@abeforgit
Copy link

While #9 is marked as solved, I still have that issue. However, the workaround mentioned there to add the module definition like so:

// global.d.ts

declare module 'diary' {
    export * from 'diary/types/index';
}

works well. So this is not really blocking, but it being a fully typescript library it's a bit weird to have to add these module definitions.

Environment

I am running a bit of a weird setup so this might be the cause

node: v14.16.0
npm: 6.4.11
typescript: 3.9.1-rc

It is also an emberJS project, which has its own rather opaque build system

@maraisr
Copy link
Owner

maraisr commented Jun 19, 2021

Hi @abeforgit thanks for the issue! Yeah that isnt the greatest DX for sure. But in 0.1.4 we did release a fix that made it so the typings all work as it should.

But in saying that i see you're using TypeScript 3 — maybe all i need to do is check when typeVersions as introduced and set that is its version, currently its > 4

@abeforgit
Copy link
Author

ah yes thatll be it
I'll see if I can't make a pr to support lower ts versions, upgrading is a bit of a battle on our end

@abeforgit
Copy link
Author

I'd suggest adding to the README that currently only ts >4 is supported, I'd consider this issue as resolved then

@maraisr
Copy link
Owner

maraisr commented Jun 21, 2021

I don't think any of the TypeScript itself is a hard and fast v4+, do you mind helping me test this? Can you open up node_modules/diary/package.json and change the typeVersions to >3 ald let me know if that works for you.

If that works we can surely raise a PR.

@abeforgit
Copy link
Author

abeforgit commented Jun 22, 2021

Taking the version down works indeed, but it's not quite that simple. Taking the version down implies we would support that version of typescript, which is actually quite annoying to verify if we want to keep developing using the latest typescript compiler.
Reference here: microsoft/TypeScript#31907
There is this package: https://github.com/sandersn/downlevel-dts which attempts to automatically create "polyfills" for older typescript versions, but it's not perfect and they explicitly say you'd need to verify it manually with the specific tsc version.

According to this comment there are no plans to provide any native support for this in typescript.

On the other hand, since this is really only an issue about types, not about functionality, it wouldn't be too bad to just kind of assume things will work and handle issues as they appear. Typescript should also be one of the easier packages to upgrade since as long as it compiles it shouldn't interfere with the way the program works.

I had no idea packaging ts projects was this much of a pain 😅 this is my first experience with it

@abeforgit
Copy link
Author

In any case if you do end up going for it I'd suggest targeting 3.4 or higher, to keep the option for using downlevel-dts open

@abeforgit
Copy link
Author

Fyi I did end up just updating our typescript version to latest, it was not painful at all :) for me you can close this issue, maybe still add a hint in the readme that if people need support for lower versions they can raise an issue?

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

2 participants