Skip to content

Commit

Permalink
fix: type generation for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jan 12, 2024
2 parents 639bce1 + 293a7cb commit b484b39
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions generate-types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ const printError = (diagnostic) => {
jsdoc.length > 0 &&
jsdoc[0].kind === ts.SyntaxKind.JSDocParameterTag
) {
jsdocParamDeclaration = /** @type {ts.JSDocParameterTag} */ (jsdoc[0]);
jsdocParamDeclaration = /** @type {ts.JSDocParameterTag} */ (
jsdoc[0]
);
}
}
const type = getTypeOfSymbol(p, false);
Expand Down Expand Up @@ -805,10 +807,8 @@ const printError = (diagnostic) => {
if (typeNode && !isNodeModulesSource(typeNode.getSourceFile())) {
switch (typeNode.kind) {
case ts.SyntaxKind.IndexedAccessType: {
const {
objectType,
indexType,
} = /** @type {ts.IndexedAccessTypeNode} */ (typeNode);
const { objectType, indexType } =
/** @type {ts.IndexedAccessTypeNode} */ (typeNode);
const objectTypeType = checker.getTypeAtLocation(objectType);
/** @type {any} */ (objectTypeType)._typeNode = objectType;
const indexTypeType = checker.getTypeAtLocation(indexType);
Expand All @@ -824,10 +824,8 @@ const printError = (diagnostic) => {
break;
}
case ts.SyntaxKind.TypeReference: {
const {
typeArguments,
typeName,
} = /** @type {ts.TypeReferenceNode} */ (typeNode);
const { typeArguments, typeName } =
/** @type {ts.TypeReferenceNode} */ (typeNode);
const typeArgumentsTypes = typeArguments
? typeArguments.map((node) => {
const type = checker.getTypeAtLocation(node);
Expand Down Expand Up @@ -1018,9 +1016,10 @@ const printError = (diagnostic) => {
}
} else {
if (isSourceFileModule(externalSource)) {
const match = /^(.+\/node_modules\/(?:@types\/)?)((?:@[^/]+\/)?[^/]+)(.*?)(\.d\.ts)?$/.exec(
externalSource.fileName
);
const match =
/^(.+\/node_modules\/(?:@types\/)?)((?:@[^/]+\/)?[^/]+)(.*?)(\.d\.ts)?$/.exec(
externalSource.fileName
);
if (!match) {
console.error(
`${externalSource.fileName} doesn't match node_modules import schema`
Expand Down Expand Up @@ -2134,9 +2133,9 @@ const printError = (diagnostic) => {
parsed.type === "typeof class" ? parsed.correspondingType : type;
const variable = typeToVariable.get(classType);
queueDeclaration(classType, variable, () => {
const parsed = /** @type {MergedClassType} */ (parsedCollectedTypes.get(
classType
));
const parsed = /** @type {MergedClassType} */ (
parsedCollectedTypes.get(classType)
);
const typeArgs = new Set(parsed.typeParameters);
return `declare ${
parsed.constructors.length === 0 ? "abstract class" : "class"
Expand Down Expand Up @@ -2251,8 +2250,9 @@ const printError = (diagnostic) => {
const variable = typeToVariable.get(type);
addImport(parsed.exportName, variable, parsed.from);
return (
(parsed.isValue && state !== "with type args" ? "typeof " : "") +
variable
(parsed.isValue && !type.isClass() && state !== "with type args"
? "typeof "
: "") + variable
);
}
}
Expand Down

0 comments on commit b484b39

Please sign in to comment.