-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Allow augmentation of re-exported module #12607
Comments
Also, not being able to augment a re-exported module can cause confusion (eg: #11406) but does not necessarily have an obvious solution as per @RyanCavanaugh comment |
so, is this your library? or a library you are using? one thing to note, ES2015 does not allow augmenting on the top level of a module anyways. so moving forward the only augmentation allowed at runtime is augmenting export shapes themselves. |
Hi @mhegazy thanks for the quick reply. Let's suppose this is a library I'm using that's been authored by someone else. In reality, I hit this issue whilst writing a demo app of a library that I'm authoring. I spent 2 hours banging my head thinking I was going crazy! In my case I was trying to augment an interface re-exported from ng-table |
There was a similar discussion at #9532 (comment). The only workaround I'm aware of is to augment the specific module instead of the exported one but that has all the caveats you mentioned. E.g. |
Yup that is the workaround, but not a particularly satisfying one. It means the author loses the freedom to rearrange modules inside a package. The consumer also has to know the "internal" paths. |
I've hit the same problem. It is important to have a solution to this problem. |
I've just hit this problem too. I'd like to augment Tried many ways, without success, such as: declare namespace THREE {
export interface Object3D {/* augmentations */}
} declare module 'three' {
export interface Object3D {/* augmentations */}
} declare module 'three/three-core' {
export interface Object3D {/* augmentations */}
} Any workaround for this would be appreciated! |
Ah, this is why it's not working. I'm trying to do the same thing as @endel (augmenting a re-exported class from the package-scoped EDIT, this worked for me: declare module 'three/three-core' {
interface Object3D {/* augmentations */}
} |
I keep running into this issue over again, forgetting that I can't augment re-exported modules. Would be great if this were fixed. |
The OP is slightly ambiguous so I'll address both. If the request is to allow the exporting library to create a new type that augments If the request is that augmentors can augment the exported |
duplicate of #8545? |
It is important to fix this issue because, as @christianacca said, "the [library] author loses the freedom to rearrange modules inside a package". Notice also the inconsistency: for a consumer of a package, to use a re-exported type you just specify the package name and the type name: import {Type} from "library" To augment, however, you have to know where this type definition resides within the source tree of the library: declare module "library/src/dir1/dir2/file"
{
interface Type
{
}
} |
Very maddening bug... it should be documented at least somewhere the current limitation. I've wasted hours on this bug, finally found this issue to explain some of this. Three.js is organized is such a way that augmentation will fail as others mentioned. |
Is this still happening? I think as long as the declared module path and the import path are the same, it works now. |
No, I don't think this is working. e.g. in https://github.com/pmndrs/valtio, the declare module 'valtio' {
export function useSnapshot<T extends object>(p: T): T
} does not augment the module, but overwrites it. Is the above code correct? If it is, are there any known workarounds? ref: pmndrs/valtio#458 |
I've sadly discovered that it not possible to augment a ES2015 module that is being re-exported. At least not without specifying the full path to the ES2015 that is then being re-exported.
This has significant implications, particularly for library authors and consumers.
An example would probably help clarify.
Suppose as an authored of a library I want to expose a simple surface area from which consumers should import from. I do this by creating an index.ts file that re-exports modules from nested sub-folders like so:
Now a consumer can import like so:
The benefits of the above:
Once augmentation enters the picture all of the above benefits are now gone.
This is really bad for everyone.
What can be done about the situation?
Thanks
Christian
The text was updated successfully, but these errors were encountered: