diff --git a/.chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md b/.chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md new file mode 100644 index 0000000000..947d8feafe --- /dev/null +++ b/.chronus/changes/fix-clone-type-donot-finish-unfinished-2024-5-11-21-54-41.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/compiler" +--- + +[API] Do not run decorators on cloned type if the original type wasn't finished diff --git a/packages/compiler/src/core/checker.ts b/packages/compiler/src/core/checker.ts index 8beba6c45f..37f2edcfad 100644 --- a/packages/compiler/src/core/checker.ts +++ b/packages/compiler/src/core/checker.ts @@ -6512,7 +6512,10 @@ export function createChecker(program: Program): Checker { * recursively by the caller. */ function cloneType(type: T, additionalProps: Partial = {}): T { - const clone = finishType(initializeClone(type, additionalProps)); + let clone = initializeClone(type, additionalProps); + if (type.isFinished) { + clone = finishType(clone); + } const projection = projectionsByType.get(type); if (projection) { projectionsByType.set(clone, projection);