Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript "inferred type ... exceeds maximum" error with Exact #449

Closed
jacobfederer opened this issue Dec 21, 2021 · 8 comments
Closed

Comments

@jacobfederer
Copy link

I'm trying to distribute the generated proto classes/constants inside a npm library. Therefore I need to compile the Typescript code into JS using tsc. However this fails due to an tsc error:

proto/abc.ts:3398:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

3398 export const SomeMessage = {
                  ~~~~~~~~~~~~~~~~~~~~~

proto/abc.ts:3531:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

3531 export const AnotherConstMessage = {
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

proto/abc.ts:3620:14 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

3620 export const AnotherConstMessage = {
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My first idea was to shorten the proto files and to move messages into more files, but this doesn't seem to help.

How can I attach a "type annotation" ? Is there a way to distribute Typescript files without compiling them?

@stephenh
Copy link
Owner

Wow, how many fields do you have in you messages?

I suppose we could detect "this message has more than N fields" and then output an explicit type annotation for it.

...I almost wonder if we shouldn't just use a class, b/c even though "just data / interfaces" is one of ts-proto's design goals, admittedly at the end of the day, with TS's structural typing, as long as you don't have private fields, I'm ~pretty sure we could output class here (to avoid repeating the type + impl, which is what a class basically does), and have code that works with the SomeMessage be none-the-wiser about whether it was defined as a class or const...

@jacobfederer
Copy link
Author

jacobfederer commented Dec 30, 2021

Not a lot, in one message that fails to compile I only have 5 fields. But I suspect that this might be an issue due to the use of recursion.

Other people solved the issue by altering their recursive function/combined type use: Stackoverflow, microsoft/TypeScript#43817

Regarding the class usage: When I first go started with the library the separation of data/implementation confused me a bit. It might be easier to use if both are together in one class.

If you want, I can give you access to our proto library.

@jacobfederer
Copy link
Author

jacobfederer commented Dec 30, 2021

I tried commenting the fromPartial<I extends Exact<DeepPartial<XYZ>, I>> method out on one of the constants and it might have actually worked since Exact seems to be the problematic/recursive element in the generated files.

@stephenh
Copy link
Owner

stephenh commented Jan 1, 2022

@jacobfederer we just added an option to disable the Exact type, see #454; can you try enabling that option and see if that fixes it for you?

If it does, it'd be really great to have a minimal *.proto that reproduces the compile error, to see if it's something that we could fix in the Exact types.

Thanks!

@jacobfederer
Copy link
Author

@stephenh I tested it yesterday, it works well. Tsc compiled it a lot faster.

I'll provide a minimal reproduction when I'm back from my holidays (start of the next week).

@tidhar-ziv
Copy link

Generating code from Temporal.io API (https://github.com/temporalio/api/tree/master/temporal/api) will produce JS code failing with the same error, if using a ts-proto version later than 1.91.0

@mvniekerk
Copy link

Confirming last working version was 1.91.0

@stephenh stephenh changed the title Typescript compiler fails to compile ts_proto generated files to js Typescript "inferred type ... exceeds maximum" error with Exact Jul 1, 2023
@stephenh
Copy link
Owner

stephenh commented Jul 1, 2023

Late reply, but right @mvniekerk the Exact type was introduced in v1.91.0 but can be disabled with --ts_proto_opt=useExactTypes=false if it causes issues in your output.

Tkd-Alex added a commit to sentinel-official/sentinel-js-sdk that referenced this issue Feb 20, 2024
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

No branches or pull requests

4 participants