- Notifications
You must be signed in to change notification settings - Fork 1k
Add type compatibility test between SDK and spec types #729
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
base: main
Are you sure you want to change the base?
Conversation
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.
some comments after a quick scan , will review today/tomorrow
src/spec.types.test.ts Outdated
} | ||
function checkResourceReference( | ||
sdk: RemovePassthrough<SDKTypes.ResourceReference>, | ||
spec: SpecTypes.ResourceTemplateReference |
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.
should it be resource? (SpecTypes.ResourceReference
)
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.
Oh good catch! Actually ResourceReference now only exists in the SDK and is aliased to ResourceTemplateReference, which is already tested. Removed checkResourceReference
.gitignore Outdated
@@ -69,6 +69,9 @@ web_modules/ | |||
# Output of 'npm pack' | |||
*.tgz | |||
| |||
# Output of 'npm run fetch:spec-types' | |||
src/spec.types.ts |
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.
is there a way to do it without creating a file in src?
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.
Good point thx, moved it to top-level which is only marginally better. Happy to create another tmp dir if you think it's cleaner (dist seems a no-go)
… / aliased to ResourceTemplateReference)
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.
Thanks!!
.gitignore Outdated
@@ -69,6 +69,9 @@ web_modules/ | |||
# Output of 'npm pack' | |||
*.tgz | |||
| |||
# Output of 'npm run fetch:spec-types' | |||
src/spec.types.ts |
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.
Good point thx, moved it to top-level which is only marginally better. Happy to create another tmp dir if you think it's cleaner (dist seems a no-go)
src/spec.types.test.ts Outdated
} | ||
function checkResourceReference( | ||
sdk: RemovePassthrough<SDKTypes.ResourceReference>, | ||
spec: SpecTypes.ResourceTemplateReference |
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.
Oh good catch! Actually ResourceReference now only exists in the SDK and is aliased to ResourceTemplateReference, which is already tested. Removed checkResourceReference
Test that the TS SDK types are in sync w/ the Spec types
Note: ModelHint, ModelPreferences, Annotations are not in the SDK yet, incubating them in a63aeeb
Motivation and Context
#727 cc/ @ihrpr
How Has This Been Tested?
Checked that
npm run test
failes w/ human-readable message before Rename reject to decline #727Did spot tests of editing either the sdk types or the spec types, e.g. switching fields between optional & required, renaming, altering strings
Breaking Changes
None
Types of changes
Checklist
Additional context
Types in the TS SDK are derived from Zod schemas, while the ones in the specs are written by hand. This causes a few type discrepancies, which are temptatively ironed out using ham-handed type mappings:
ZodObject.passthrough()
feature introduces{[key: string]: unknown}
passthroughs: we undo this w/RemovePassthrough<T>
z.unknown()
are treated as optional; we undo this w/MakeUnknownsNotOptional<T>
, with the exception of_meta
fields