Skip to content

Conversation

@remcohaszing
Copy link
Member

One of the big features of TypeScript, is that it can infer types based on context. This is powerful, but it comes at a cost. Determining types based on inference consumes much more resources than using a type annotation. This is an important reason to add explicit type annotations.

We heavily rely on Zod though. Zod is powerful, but it heavily relies on inference. This means that by using Zod, we sacrifice type checking performance. Zod 4 will supposedly be more performant. This is great, but by definition it can’t be as performant as regular types.

When the types become really complex, TypeScript may error on this. An explicit type annotation in the right spot fixes this. This PR uses this to resolve the type error. I can’t explain why this surfaced here, but not in our internal repos these schemas originate from.

One of the big features of TypeScript, is that it can infer types based
on context. This is powerful, but it comes at a cost. Determining types
based on inference consumes much more resources than using a type
annotation. This is an important reason to add explicit type
annotations.

We heavily rely on Zod though. Zod is powerful, but it heavily relies on
inference. This means that by using Zod, we sacrifice type checking
performance. Zod 4 will supposedly be more performant. This is great, but
by definition it can’t be as performant as regular types.

When the types become really complex, TypeScript may error on this. An
explicit type annotation in the right spot fixes this. This PR uses this
to resolve the type error. I can’t explain why this surfaced here, but
not in our internal repos these schemas originate from.
@remcohaszing remcohaszing requested a review from kvz May 7, 2025 13:03
@kvz kvz merged commit 4160d1c into sync-alphalib-2025-05-06 May 7, 2025
6 checks passed
@kvz kvz deleted the fix-deep-types-error branch May 7, 2025 13:11
kvz added a commit that referenced this pull request May 7, 2025
* w

* w

* Update template.ts

* Fix deep types error (#227)

* Fix deep types error

One of the big features of TypeScript, is that it can infer types based
on context. This is powerful, but it comes at a cost. Determining types
based on inference consumes much more resources than using a type
annotation. This is an important reason to add explicit type
annotations.

We heavily rely on Zod though. Zod is powerful, but it heavily relies on
inference. This means that by using Zod, we sacrifice type checking
performance. Zod 4 will supposedly be more performant. This is great, but
by definition it can’t be as performant as regular types.

When the types become really complex, TypeScript may error on this. An
explicit type annotation in the right spot fixes this. This PR uses this
to resolve the type error. I can’t explain why this surfaced here, but
not in our internal repos these schemas originate from.

* Update src/alphalib/types/template.ts

---------

Co-authored-by: Kevin van Zonneveld <vanzonneveld@gmail.com>

---------

Co-authored-by: Remco Haszing <remcohaszing@gmail.com>
@kvz
Copy link
Member

kvz commented May 15, 2025

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