-
Notifications
You must be signed in to change notification settings - Fork 427
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
feat(codegen): expose referenced type as hidden symbol #6008
feat(codegen): expose referenced type as hidden symbol #6008
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
No changes to documentation |
Component Testing Report Updated Mar 19, 2024 3:34 PM (UTC)
|
015f4f6
to
ad928d6
Compare
6b34289
to
9445143
Compare
ad928d6
to
26ad046
Compare
b9b5ea4
to
28a69e5
Compare
26ad046
to
84eede0
Compare
28a69e5
to
9d325f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this pattern. It's very akin to the use of Symbol.iterator
etc
I wonder if we should declare some kind of object to act as a symbol namespace. e.g.
declare const CodegenSymbol = {
referenceTo: unique symbol
}
Then usage could be like:
interface SomeType {
_type: 'ref';
[CodegenSymbol.referenceTo]?: 'sanity.imageAsset';
// ...
}
But not a blocker. Just an idea. It may not even work because the object implies a runtime value.
Alternative idea: you could export a type helper from the Instead of: type myQueryResult = {
asset?: {
_ref: string;
_type: "reference";
_weak?: boolean;
[internalGroqTypeReferenceTo]?: "sanity.imageAsset";
};
// ...
} it could be: import {type SanityReference} from '@sanity/codegen'
type myQueryResult = {
asset?: SanityReference<'sanity.imageAsset'>;
// ...
} type SanityReference<TReferenceType extends string> = {
_ref: string;
_type: "reference";
_weak?: boolean;
[__internalGroqTypeReferenceTo]?: TReferenceType;
} |
84eede0
to
4ce884e
Compare
8844996
to
01fc82d
Compare
4ce884e
to
0a18f59
Compare
01fc82d
to
53dde4e
Compare
0a18f59
to
037d8b8
Compare
53dde4e
to
59fd242
Compare
037d8b8
to
f1da568
Compare
59fd242
to
beeca7e
Compare
f1da568
to
4d9d54c
Compare
beeca7e
to
6975a93
Compare
4d9d54c
to
f451330
Compare
6975a93
to
dca8116
Compare
dca8116
to
e60bdf9
Compare
Description
Adds a symbol so that we can lookup which type a reference is referencing to.
Types generating ends up like:
What to review
Testing
No specific tests added for this as the feature is marked as "internal". We should build out general integration testing for codegen, but that can be done separately.
Notes for release
N/A - no notes needed.