Skip to content

Commit c09df85

Browse files
authored
Merge pull request #228 from arethetypeswrong/bug/222
Filter `prototype` from expected named exports
2 parents 953e617 + 5f96cdc commit c09df85

File tree

4 files changed

+405
-17
lines changed

4 files changed

+405
-17
lines changed

.changeset/breezy-avocados-deny.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": patch
3+
---
4+
5+
Filter `prototype` from expected named exports

packages/core/src/internal/checks/namedExports.ts

+27-17
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,22 @@ export default defineCheck({
3838
}
3939

4040
const typeChecker = host.createAuxiliaryProgram([typesFileName]).getTypeChecker();
41-
const expectedNames = typeChecker
42-
.getExportsAndPropertiesOfModule(typesSourceFile.symbol)
43-
// @ts-expect-error `getSymbolFlags` extra arguments are not declared on TypeChecker
44-
.filter((symbol) => typeChecker.getSymbolFlags(symbol, /*excludeTypeOnlyMeanings*/ true) & ts.SymbolFlags.Value)
45-
.map((symbol) => symbol.name);
41+
const expectedNames = Array.from(
42+
new Set(
43+
typeChecker
44+
.getExportsAndPropertiesOfModule(typesSourceFile.symbol)
45+
.filter((symbol) => {
46+
return (
47+
// TS treats `prototype` and other static class members as exports. There's possibly
48+
// a fix to be done in TS itself, since these show up as auto-imports.
49+
symbol.name !== "prototype" &&
50+
// @ts-expect-error `getSymbolFlags` extra arguments are not declared on TypeChecker
51+
typeChecker.getSymbolFlags(symbol, /*excludeTypeOnlyMeanings*/ true) & ts.SymbolFlags.Value
52+
);
53+
})
54+
.map((symbol) => symbol.name),
55+
),
56+
);
4657

4758
// Get actual exported names as seen by nodejs
4859
let exports: readonly string[] | undefined;
@@ -51,20 +62,19 @@ export default defineCheck({
5162
} catch {
5263
// If this fails then the result is indeterminate. This could happen in many cases, but
5364
// a common one would be for packages which re-export from another another package.
65+
return;
5466
}
5567

56-
if (exports) {
57-
const missing = expectedNames.filter((name) => !exports.includes(name));
58-
if (missing.length > 0) {
59-
const lengthWithoutDefault = (names: readonly string[]) => names.length - (names.includes("default") ? 1 : 0);
60-
return {
61-
kind: "NamedExports",
62-
implementationFileName,
63-
typesFileName,
64-
isMissingAllNamed: lengthWithoutDefault(missing) === lengthWithoutDefault(expectedNames),
65-
missing,
66-
};
67-
}
68+
const missing = expectedNames.filter((name) => !exports.includes(name));
69+
if (missing.length > 0) {
70+
const lengthWithoutDefault = (names: readonly string[]) => names.length - (names.includes("default") ? 1 : 0);
71+
return {
72+
kind: "NamedExports",
73+
implementationFileName,
74+
typesFileName,
75+
isMissingAllNamed: lengthWithoutDefault(missing) === lengthWithoutDefault(expectedNames),
76+
missing,
77+
};
6878
}
6979
},
7080
});
222 KB
Binary file not shown.

0 commit comments

Comments
 (0)