-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
UnsupportedSyntaxError: namespace child (hoisting) not supported #162
Comments
I experimented with fixing this, but rollup flattens all the imports into the global namespace, and typescript does not allow re-declarations, which is super annoying, as this generated code fails in typescript:
|
@Swatinem If it flattens all imports then is there a way to redeclare a namaspace? // Child.ts
export namespace Child {
export type SomeType = 'Something'
}
// Main.ts
import { Child as ChildTemp } from './Child.ts'
export namespace Main {
export import Child = ChildTemp
} |
Maybe there is, but I doubt its worth the effort. |
I was about to file a similar issue and during my tests I even found a simpler scenario without namespaces not being supported. Am I right with my assumption that these problems relate I guess solving the following issue, should also fix the exports within namespaces: // test.d.ts
export declare class Test {}
// input.d.ts
import * as _Test from './test';
export import Test = _Test.Test; Will lead to:
Rollup already seems to have some renaming mechanism in case we have name clashes: // test.d.ts and test2.d.ts
export declare class Test {}
// input.d.ts
import * as _Test from './test';
import * as _Test2 from './test2';
export declare const fakeNS: {
Test: typeof _Test.Test;
Test2: typeof _Test2.Test;
};
// output.d.ts
declare class Test$1 {}
declare class Test {}
declare const fakeNS: {
Test: typeof Test$1;
Test2: typeof Test;
};
export { fakeNS }; If we can "activate" it somehow that the name of the export is already taken, there will happen a renaming and we can generate this: // test.d.ts
export declare class Test {}
// input.d.ts
import * as _Test from './test';
export import Test = _Test.Test;
// output.d.ts
declare class Test$1 { }
export import Test = Test$1; This would then also work if we have the |
I hit this issue from
And this throws the error mentioned above. Is there any workaround to this? I see the |
Why this wontfix |
Still got this on 2023. why the hack this won't fix? |
Svelte 4's new d.ts file could hit this issue. https://hyrious.me/npm-browser/[email protected]/package/types/index.d.ts:276 declare module 'svelte/compiler' {
import type { AssignmentExpression, Node, Program } from 'estree';
import type { SourceMap } from 'magic-string';
... |
I'm hitting this issue with Svelte 4 now, like @hyrious points out:
Is there a solution for this? |
Did you solve this? it seems like you did |
@ryanbas21 basically:
It feels a bit like a waste adding dependencies just for their types, but on the other hand, it is also neat not to publish duplicated types. I've seen some npm packages starting to publish their TypeScript types in a separate package, that may be a good idea. |
I'm having the same issue because I'm importing import type {CompilerHost} from "typescript" Will lead to (with
|
Checklist
Other plugins, such as
node-resolve
are known to cause issues..d.ts
files generated by TypeScript.The plugin can consume
.ts
and even.js
files (withallowJs: true
), but this is known to cause issues.@types
.The plugin ignores these by default, unless
respectExternal
is set.@types
can contain hand-crafted code which is known to cause issues.Code Snipped
Error Message
The text was updated successfully, but these errors were encountered: