diff --git a/.chronus/changes/types_order-2024-9-31-14-3-9.md b/.chronus/changes/types_order-2024-9-31-14-3-9.md new file mode 100644 index 0000000000..9cdc6f9010 --- /dev/null +++ b/.chronus/changes/types_order-2024-9-31-14-3-9.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +use array instead of set to make the types ordered by typespec definition \ No newline at end of file diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index 22224e9904..72a7796aae 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -1752,15 +1752,17 @@ function filterOutTypes( context: TCGCContext, filter: number, ): (SdkModelType | SdkEnumType | SdkUnionType | SdkNullableType)[] { - const result = new Set(); + const result = new Array(); for (const sdkType of context.referencedTypeMap?.values() ?? []) { // filter models with unexpected usage if ((sdkType.usage & filter) === 0) { continue; } - result.add(sdkType); + if (!result.includes(sdkType)) { + result.push(sdkType); + } } - return [...result]; + return result; } export function getAllModelsWithDiagnostics(