-
Notifications
You must be signed in to change notification settings - Fork 68
[TCGC] Fix: Allow custom encoding strings in SdkDateTimeTypeBase and SdkDurationType #3501
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
Conversation
…rationType Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
tadelesh
left a comment
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.
@copilot Resolve the comments. Make sure pnpm run build and pnpm run test pass. Use pnpm -w change add to add changeset. Format the code with pnpm -w format:dir packages/typespec-client-generator-core.
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Changes applied in commit 4e757f1:
Note: Full build requires core submodule dependencies. The type changes are correct and tests for the modified functionality pass. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
.chronus/changes/fix-encode-custom-string-support-2025-11-11-07-28-39.md
Outdated
Show resolved
Hide resolved
tadelesh
left a comment
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.
Please hold merge before TypeSpec Nov. release.
commit: |
|
According to the decision here, TCGC decided to transparent pass the encode to language's emitter. Language's emitter could choose the behavior for unknown encode. |
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.
potentially break emitter due to the type of encode
tadelesh
left a comment
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.
@copilot Merge main and resolve conflict.
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Successfully merged main branch and resolved conflicts in commit 95cd867. The conflict in |
…/typespec-azure into copilot/fix-undefined-encode-issue
tadelesh
left a comment
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.
@copilot Update test to use latest test framwork according to other tests.
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Updated tests to use the latest test framework in commit 26b394e. Changed from |
Fix SdkDateTimeTypeBase.encode to support custom encoding strings
Plan
SdkDateTimeTypeBase.encodetype toDateTimeKnownEncoding | stringin interfaces.tsSdkDurationType.encodetype toDurationKnownEncoding | stringfor consistencypnpm -w formatpnpm -w change addIssue
The
@encodedecorator supports string values for arbitrary encodings, butSdkDateTimeTypeBaseandSdkDurationTypedefineencodeasDateTimeKnownEncoding/DurationKnownEncoding. When a custom encoding is used (not one of the known values), this creates a type mismatch.Solution
Changed the type of the
encodeproperty to use union typesDateTimeKnownEncoding | stringandDurationKnownEncoding | stringto allow custom encoding values while maintaining better type safety for known encodings. This aligns with the compiler's support for custom encoding strings.Changes Made
interfaces.ts: Updated type definitions with union types and incorporated new documentation comments from main branch
SdkDateTimeTypeBase.encode:DateTimeKnownEncoding→DateTimeKnownEncoding | stringSdkDurationType.encode:DurationKnownEncoding→DurationKnownEncoding | string/** How to encode the type on wire. */comment from main branchDurationKnownEncodingimport for union typeisSdkDateTimeEncodings()type guard for backward compatibilitytypes.ts: Removed unnecessary type casts
as DateTimeKnownEncodingcastsas DurationKnownEncodingcastsTests: Added coverage for custom encodings and updated to latest test framework
date-time.test.ts: Added test for custom encoding string on utcDateTime usingSimpleTesterWithService.compile()andcreateSdkContextForTester()duration.test.ts: Added test for custom encoding string on duration usingSimpleTesterWithService.compile()andcreateSdkContextForTester()Changeset: Added fix changeset for typespec-client-generator-core
Merge: Successfully merged main branch and resolved conflicts
Test Results
✅ Tests updated to use latest framework
✅ Code formatted
✅ Changeset added
✅ Main branch merged with conflicts resolved
✅ No breaking changes - union type is backward compatible
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.