chore(templates): add type detection on getGlobal utility #11617
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Added proper type detection to the global data fetching utilities in the form builder example. Enhanced the getGlobal and getCachedGlobal functions to leverage TypeScript generics for improved type safety.
Why?
This change improves developer experience by providing proper TypeScript type inference when working with global data. With these changes:
The returned data from getGlobal is now properly typed as DataFromGlobalSlug based on the slug parameter
TypeScript can now correctly infer the return type of getCachedGlobal based on the global slug
This prevents type errors and provides better IDE autocomplete/IntelliSense when accessing properties on retrieved global data
How?
Added import for the DataFromGlobalSlug type from Payload
Made getGlobal a generic function that accepts a type parameter T extends Global
Added proper return type annotation (Promise<DataFromGlobalSlug>) to the getGlobal function
Updated getCachedGlobal to use the same generic typing pattern
These changes maintain the same runtime behavior while enhancing type safety