Conversation
…tionalProperties for record models Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
extends Record<string, T> instead of additionalProperties property for record models
|
@copilot pull the latest from main and then Fix failing tests in http-client-js |
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
|
@copilot pull the latest changes from the main branch and run pnpm format to fix any format issues in changed files |
…ilot/fix-emit-additional-properties
|
@copilot also fix any issues in the e2e tests that are failing |
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Merged the latest changes from main and ran 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:
|
…ectly instead of wrapping in additionalProperties Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
…s skipping extends Record Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Fixed the e2e test failures in commits 9b066b1 and 789af83. The root cause was that while the interface declarations were updated to use Changes made:
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:
|
There was a problem hiding this comment.
@copilot also please:
- pull the latest from main
- ensure that all tests are passing and correct any issues
- Add additional tests to cover multiple record spreads:
model Foo { id: int32; ...Record<string>; ...Record<float32>}which should result in additionalProperties that are of type Record <string, string | float32> - ensure that all files use correct formatting (pnpm format)
| }`); | ||
| }); | ||
|
|
||
| it("omits extends clause when known properties are incompatible with the record element type", async () => { |
There was a problem hiding this comment.
In this case, you should revert to using additionalProperties again
There was a problem hiding this comment.
Reverted to additionalProperties for the incompatible case in commit c0acb37. When named properties are not assignable to the record element type, the interface now uses additionalProperties?: Record<string, T> instead of omitting the extends clause. Compatible types still use extends Record<string, T>.
…ord types, use extends Record for compatible types
- InterfaceBody now adds additionalProperties?: Record<string, T> when named properties are incompatible with the record element type (TypeScript index signature constraint)
- getExtendsType already skips extends clause for incompatible cases
- json-model-additional-properties-transform uses wrapper approach (input_.additionalProperties) for incompatible types and flat approach (destructuring) for compatible types
- Added multiple record spreads test (model Foo { id: int32; ...Record<string>; ...Record<float32> }) showing union additionalProperties
- Updated test snapshots to reflect new behavior
- Updated e2e tests to use additionalProperties wrapper for DifferentSpread/MultipleSpread types
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done in commit c0acb37:
|
extends Record<string, T> instead of additionalProperties property for record modelsextends Record<string, T> for compatible types, additionalProperties for incompatible types
Fixes the TypeScript Emitter Framework to correctly represent TypeSpec models with additional properties using TypeScript-idiomatic syntax based on type compatibility.
Behavior
model X extends Record<unknown> { id: string; }interface X extends Record<string, unknown> { id: string; }model X { name: string; ...Record<string>; }interface X extends Record<string, string> { name: string; }← all properties assignable to Tmodel X { id: int32; ...Record<string>; }interface X { id: number; additionalProperties?: Record<string, string>; }← incompatible typesmodel X { id: int32; ...Record<string>; ...Record<float32>; }interface X { id: number; additionalProperties?: Record<string, string | number>; }← multiple spreadsChanges Made
interface-declaration.tsx:getExtendsTypeusesextends Record<string, T>only when all named properties are assignable toT.InterfaceBodyaddsadditionalProperties?: Record<string, T>when named properties are incompatible with the record indexer type (TypeScript index signature constraint).json-model-additional-properties-transform.tsx: AddedusesWrappedAdditionalPropertieshelper that walks the model inheritance chain to determine whether to use the flat (destructuring) or wrapper (input_.additionalProperties) serialization approach.interface-declaration.test.tsx: Updated tests to cover compatible types (extends Record<string, T>), incompatible types (additionalProperties?: Record<string, T>), and multiple record spreads producing unionadditionalProperties.spread.md,model_additional_properties.md,discriminated_union_spread.md): Updated to reflect the new interface shapes and serializer behavior.main.test.ts,spreads.test.ts): Compatible types (ExtendsUnknown*,SpreadString,SpreadFloat,SpreadModel, etc.) use flat structure; incompatible types (DifferentSpread*,MultipleSpread,SpreadRecordNonDiscriminatedUnion*) useadditionalPropertieswrapper.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.