'Issue with Typescript exported namespaces and rollup
I am converting some projects that used webpack to vite. I'm having a weird issue where rollup doesn't seem to recognize exported namespaces. Had no issues before with webpack.
Here is an example:
// types.ts
export namespace Test {
export interface Tester {
field: string;
}
}
export interface TestInterface {
field: string;
}
// index.ts
import {Test, TestInterface} from './types.ts';
If I do it like this I get an error saying:
'Test' is not exported by ./types.ts
However it works correctly if I change the code to this:
// index.ts
import * as Types from './types.ts';
import Test = Types.Test;
import TestInterface = Types.TestInterface;
Is there another option besides having to do a wildcard import then reassigning each individually?
Solution 1:[1]
Figured it out you have to use the keyword type on the import.
import type {Test, TestInterface} from './types.ts';
I somehow skipped over the few lines that talked about it in the documentation. https://vitejs.dev/guide/features.html#typescript
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pitchinnate |
