Skip to content

fix: ts serialization crash#9

Closed
kehindeBankole wants to merge 2 commits intomainfrom
fix/ts-serialization-crash
Closed

fix: ts serialization crash#9
kehindeBankole wants to merge 2 commits intomainfrom
fix/ts-serialization-crash

Conversation

@kehindeBankole
Copy link
Copy Markdown
Contributor

ISSUE : for export const EndpointByMethod TS inferred a massive literal type which it's not able to serialize , it hit it's limit and started throwing

node_modules/@risemaxi/api-client/src/contract.ts:8503:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

8503 export const EndpointByMethod = {
                  ~~~~~~~~~~~~~~~~


Found 1 error in node_modules/@risemaxi/api-client/src/contract.ts:8503

SOLUTION IN PR : annotate that line so typescript does not have to infer and then serialize all the literal types

Comment on lines 28 to +38

// Avoid TS7056 by preventing a huge inferred literal type here.
const contractSource = fs.readFileSync(OUTPUT_FILE, "utf8");
const endpointByMethodPattern = /export const EndpointByMethod\s*=\s*{/;
if (endpointByMethodPattern.test(contractSource)) {
const patchedSource = contractSource.replace(
endpointByMethodPattern,
"export const EndpointByMethod: Record<string, Record<string, Endpoint>> = {"
);
fs.writeFileSync(OUTPUT_FILE, patchedSource, "utf8");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI should not be the one patching items, it should be handled by you code structure or bundler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BalogunofAfrica , can you help with exactly where you want this done please , i've not been able to figure out how to do this at a level that's not the CLI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants