Skip to content

Commit

Permalink
fixed mismatched typings
Browse files Browse the repository at this point in the history
  • Loading branch information
naman-contentstack committed Dec 23, 2024
1 parent e3c76c8 commit 3690d00
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/generateTS/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default function (userOptions: TSGenOptions) {
define_interface(contentType, options.systemFields),
"{",
["/**", "Version", "*/"].join(" "),
[`_version: `, contentType._version, ";"].join(" "),
`_version: number;`,
visit_fields(contentType.schema),
"}",
]
Expand Down Expand Up @@ -328,8 +328,13 @@ export default function (userOptions: TSGenOptions) {
return `${options.naming?.prefix}Link`;
}

function type_file() {
return `${options.naming?.prefix}File`;
function type_file(field: ContentstackTypes.Field): string {
// Check if the field is `parent_uid`
if (field.uid === "parent_uid") {
return "string | null"; // Explicitly handle `parent_uid`
}
// Default handling for other file-related fields
return "string"; // Or any other default structure
}

function type_global_field(field: ContentstackTypes.GlobalField) {
Expand Down
17 changes: 17 additions & 0 deletions src/generateTS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,20 @@ export const generateTSFromContentTypes = async ({
};
}
};

// const fun = async () => {
// const config: GenerateTSBase = {
// apiKey: "blt90b7f961dd6ed75e",
// token: "cs8dadf8eec9a363f2a3aaf809",
// region: "US",
// environment: "local",
// branch: undefined,
// host: "cdn.contentstack.io",
// tokenType: "delivery",
// includeDocumentation: true,
// systemFields: false,
// };

// return await generateTS(config);
// };
// console.log("🚀 ~ result:", fun());
3 changes: 2 additions & 1 deletion src/generateTS/stack/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export const defaultInterfaces = (prefix = "", systemFields = false) => {
tags: string[];
filename: string;
url: string;
ACL: any[];
ACL: any[] | object;
is_dir: boolean;
parent_uid: string;
_version: number;
title: string;
_metadata?:object;
publish_details: ${prefix}PublishDetails;
}`,
`export interface ${prefix}Link {
Expand Down

0 comments on commit 3690d00

Please sign in to comment.