diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bc999936e81c..884a41e5c962b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1887,7 +1887,9 @@ namespace ts { lastLocation === (location as BindingElement).name && isBindingPattern(lastLocation))) { const root = getRootDeclaration(location); if (root.kind === SyntaxKind.Parameter) { - associatedDeclarationForContainingInitializerOrBindingName = location as BindingElement; + if (!associatedDeclarationForContainingInitializerOrBindingName) { + associatedDeclarationForContainingInitializerOrBindingName = location as BindingElement; + } } } break; diff --git a/tests/cases/conformance/functions/parameterInitializersBackwardReferencing.ts b/tests/cases/conformance/functions/parameterInitializersBackwardReferencing.ts new file mode 100644 index 0000000000000..dce4818a5094e --- /dev/null +++ b/tests/cases/conformance/functions/parameterInitializersBackwardReferencing.ts @@ -0,0 +1,13 @@ +// @target: es5, es2015, esnext +// @noEmit: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/38243 + +function test0({ a = 0, b = a } = {}) { + return { a, b }; +} + +function test1({ c: { a = 0, b = a } = {} } = {}) { + return { a, b }; +} \ No newline at end of file