Skip to content
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

Fix: "Got unexpected undefined" error when using a re-exported type #7424

Merged
merged 8 commits into from Dec 19, 2021
@@ -0,0 +1,4 @@
type fuga = "fuga";
export type Baz = `${fuga}`;

//# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
export type bar = 'bar';
@@ -0,0 +1 @@
export type fuga = "fuga";
@@ -0,0 +1,2 @@
export * from "./bar";
export * from "./fuga";
@@ -0,0 +1,2 @@
import { fuga } from './hoge';
export type Baz = `${fuga}`
@@ -0,0 +1,6 @@
{
"name": "ts-types-re-exporting-aggregating",
"private": true,
"main": "dist/main.js",
"types": "dist/types.d.ts"
}
27 changes: 27 additions & 0 deletions packages/core/integration-tests/test/ts-types.js
Expand Up @@ -361,4 +361,31 @@ describe('typescript types', function () {
);
assert.equal(dist, expected);
});

it('should handle re-exporting aggregating correctly', async function () {
await bundle(
path.join(
__dirname,
'/integration/ts-types/re-exporting-aggregating/index.ts',
),
);

let dist = (
await outputFS.readFile(
path.join(
__dirname,
'/integration/ts-types/re-exporting-aggregating/dist/types.d.ts',
),
'utf8',
)
).replace(/\r\n/g, '\n');
let expected = await inputFS.readFile(
path.join(
__dirname,
'/integration/ts-types/re-exporting-aggregating/expected.d.ts',
),
'utf8',
);
assert.equal(dist, expected);
});
});
5 changes: 4 additions & 1 deletion packages/transformers/typescript-types/src/TSModuleGraph.js
Expand Up @@ -143,10 +143,13 @@ export class TSModuleGraph {
if (e.name === name) {
return this.getExport(module, e);
} else if (e.specifier) {
return this.resolveExport(
const m = this.resolveExport(
nullthrows(this.getModule(e.specifier)),
name,
);
if (m) {
return m;
}
}
}
}
Expand Down