Skip to content

Commit 94388cd

Browse files
fix: handle NodeJS prefix in union types (#26)
1 parent 3e4d924 commit 94388cd

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

generate-types/index.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,42 @@ const printError = (diagnostic) => {
917917
}
918918

919919
if (type.isUnion()) {
920+
let types = type.types;
921+
922+
const origin =
923+
/** @type {ts.UnionType & { origin: ts.UnionType } | undefined} */
924+
(type).origin;
925+
const nodeJSOriginTypes =
926+
origin &&
927+
origin.types &&
928+
origin.types.filter((item) => {
929+
if (!item.aliasSymbol) {
930+
return false;
931+
}
932+
933+
const fullEscapedName = getFullEscapedName(item.aliasSymbol);
934+
935+
if (fullEscapedName.includes("NodeJS.")) {
936+
return true;
937+
}
938+
});
939+
940+
if (nodeJSOriginTypes && nodeJSOriginTypes.length > 0) {
941+
types = types.filter((item) => {
942+
if (!item.symbol) {
943+
return true;
944+
}
945+
946+
return !isArrayBufferLike(getFullEscapedName(item.symbol));
947+
});
948+
949+
types.push(...nodeJSOriginTypes);
950+
}
951+
920952
return {
921953
type: "union",
922954
symbolName: parseName(type),
923-
types: type.types,
955+
types,
924956
typeParameters:
925957
type.aliasTypeArguments && type.aliasTypeArguments.length > 0
926958
? type.aliasTypeArguments

0 commit comments

Comments
 (0)