question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interface that shares name with namespace being dropped

See original GitHub issue

I’m loving this module so thanks @wessberg. I’m using it to take a slice out of the vscode repo and repackage as its own module.

index.ts:

export interface Something {
  type: string;
}

export namespace Something {
  export function forUseCase(): Something {
    // Something useful
  }
}

The resulting bundle’s .d.ts does not include the Something interface, only the namespace.

My use-case is in ggoodman/ts-primitives which pulls vscode source in a build script and produces a slice of the overall repo using rollup in-memory.

The issue is that for consuming libraries, the interface CancellationToken is being stripped from here https://github.com/microsoft/vscode/blob/f8014d495791145f1fac93cc0283737878272129/src/vs/base/common/cancellation.ts#L9-L25

Note that just below is export namespace CancellationToken. You can see what is being produced on unpkg.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wessbergcommented, Feb 13, 2020

This has been fixed in v1.2.17. I’ve tested a build based on cloning your ts-primitives library, and the CancellationToken is indeed preserved in the output.

1reaction
wessbergcommented, Feb 13, 2020

Hey there. Thanks for submitting this issue! I’m glad you like the library.

What you are actually touching on here is a fundamental aspect of rollup-plugin-ts which is that it will deconflict identically named bindings inside the same scope, because it is based on the fundamental assumption that the identifiers may originate from multiple SourceFiles that are brought together and may be identically named.

However, TypeScript also supports declaration merging, and this library attempts to figure out when declaration merging or function overloading is happening (in which case it must not deconflict) or not.

In this particular case, I think what’s happening is that rollup-plugin-ts mistakenly attempts to deconflict the interface from the NameSpace which leads to something like this:

interface Something {
    type: string;
}
declare namespace Something$0 {
    function forUseCase(): Something$0;
}
export { Something };

And this is not actually correct. So to fix this, I’ll need to revisit declaration merging vs deconflicting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# error when class shares name with namespace
As far as I'm aware, you can't declare a namespace variable, or new() a namespace. Foo is a type, and it's being used...
Read more >
How to fix Kubernetes namespaces stuck in the terminating state
You might try to delete it from the user interface (UI). To do so, click on the three dots shown at the right...
Read more >
How can I move an interface out of a network namespace?
If NAME is present in /var/run/netns it is umounted and the mount point is removed. If this is the last user of the...
Read more >
Introducing Linux Network Namespaces - Scott's Weblog
Assigning Interfaces to Network Namespaces · The first part, ip netns exec , is how you execute commands in a different network namespace....
Read more >
9. Namespace Management - Robin Documentation
The Kubernetes 'namespace' construct allows a cluster to be partitioned into multiple “virtual clusters”. Names of resources deployed (scoped) to a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found