-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
chore(TS): fix submodule type import #9051
Conversation
This is the only way I found to instruct TS of mutliple entry points of the build so a consumer has types for each entry point. |
How do I check that the node entry point is correctly typed? Like this? import { StaticCanvas } from "fabric/node"
new StaticCanvas().getNodeCanvas() // <= should not error? |
Yes |
A better solution could be dropping the dist folder in favor of node, web folders. |
I m not sure we support those imports
the correct import should always be:
no? |
Yes |
Generally speaking yes, but you would need to export every type from any module. Sometimes, for pretty internal exports, it's common in the TS community to import a submodule, even more for a type. For instance, in React, you often do things like: import {TextBlock, MediaBlock, TextRow, RectShape, RoundShape} from 'react-placeholder/lib/placeholders' From https://github.com/buildo/react-placeholder#customization, when you want to create your own placeholder. So it's not the most common use case, more an advanced one. Similar to this case where we want to know some grapheme info from fabric for our own font resizing logic. Of course, as consumer, you're aware that you're importing a type from an internal module and it might break in future. It's an acceptable compromise, because otherwise as fabric maintainer, you need to export the type AND to maintain it. In this case for instance, you might not want to export That's just to say it's not an anti-pattern to import a subtype module, especially to implement some low-level logic. In this specific case, if you prefer to export publicly |
I am for exposing as much as possible |
i m against exposing submodules because @ShaMan123 has proved himself prone to changing files names and file cases often. |
And that is after you tamed me |
Moving forward... |
The following code that imports a type from a submodule doesn't work as consumer of fabric.
(This was written by you @ShaMan123 ). I believed initially this was caused by our module augmentation, because VSCode would always open the augmentation file (with
declare module "fabric"
) along withfabric/dist/index.d.ts
. Indeed I said multiple times in other issues that submodule type imports don't work with module augmentation, but it seems I was wrong.Today I found out that if I remove
typesVersions
, the above imports work. I think it's because thetypesVersions
is resolving any (i.e.*
) import todist/index.d.ts
:fabric
->dist/index.d.ts
fabric/dist/src/shapes/Text/Text
->dist/index.d.ts
It should probably be
*: [dist/*]
and"types": "./index.d.ts"
as described in the official doc. For now, I've just removed the config since I'd like to understand the initial rational as well.Ironically, I found out your comment @ShaMan123 in microsoft/TypeScript#8305 (comment) while I was investigating why the submodule type import did not work. I didn't understand however the rational for
typesVersions
. After I removed, I was still able to compile fabric fine withbuild:fast
.