Skip to content

Commit fde1360

Browse files
fix: generic generation for array buffer like
2 parents f2d62d2 + bd2bea3 commit fde1360

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

generate-types/index.js

+35-3
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,31 @@ const printError = (diagnostic) => {
20492049
return items;
20502050
};
20512051

2052+
// TODO remove me when minimum supported typescript version will be 5.7
2053+
const isArrayBufferLike = (name) => {
2054+
if (
2055+
[
2056+
"Uint8Array",
2057+
"Uint8ClampedArray",
2058+
"Uint16Array",
2059+
"Uint32Array",
2060+
"Int8Array",
2061+
"Int16Array",
2062+
"Int32Array",
2063+
"BigUint64Array",
2064+
"BigInt64Array",
2065+
"Float32Array",
2066+
"Float64Array",
2067+
"DataView",
2068+
"Buffer",
2069+
].includes(name)
2070+
) {
2071+
return true;
2072+
}
2073+
2074+
return false;
2075+
};
2076+
20522077
/**
20532078
* @param {ts.Type} type the type
20542079
* @param {Set<ts.Type>} typeArgs type args specified in context
@@ -2152,13 +2177,20 @@ const printError = (diagnostic) => {
21522177
)})[]`;
21532178
}
21542179
}
2180+
2181+
const symbol = type.getSymbol();
2182+
const typeArgumentsWithoutDefaults =
2183+
symbol && isArrayBufferLike(getFullEscapedName(symbol))
2184+
? ""
2185+
: `<${parsed.typeArgumentsWithoutDefaults
2186+
.map((t) => getCode(t, typeArgs))
2187+
.join(", ")}>`;
2188+
21552189
return `${getCode(
21562190
parsed.target,
21572191
typeArgs,
21582192
"with type args",
2159-
)}<${parsed.typeArgumentsWithoutDefaults
2160-
.map((t) => getCode(t, typeArgs))
2161-
.join(", ")}>`;
2193+
)}${typeArgumentsWithoutDefaults}`;
21622194
}
21632195
case "interface": {
21642196
const variable = typeToVariable.get(type);

0 commit comments

Comments
 (0)