From f9729d2f7489efd31c415101e890be0a9e32d3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 3 Oct 2025 20:33:11 +0200 Subject: [PATCH] Port "make exported destructured discriminated union narrowing work" Co-authored-by: =?UTF-8?q?Michal=20Mar=C5=A1=C3=A1lek?= --- internal/checker/flow.go | 2 +- .../dependentDestructuredVariablesWithExport.types | 2 +- .../dependentDestructuredVariablesWithExport.types.diff | 9 --------- 3 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types.diff diff --git a/internal/checker/flow.go b/internal/checker/flow.go index 6ff6acbf4c..eafd7fde95 100644 --- a/internal/checker/flow.go +++ b/internal/checker/flow.go @@ -1427,7 +1427,7 @@ func (c *Checker) getCandidateDiscriminantPropertyAccess(f *FlowState, expr *ast // parameter declared in the same parameter list is a candidate. if ast.IsIdentifier(expr) { symbol := c.getResolvedSymbol(expr) - declaration := symbol.ValueDeclaration + declaration := c.getExportSymbolOfValueSymbolIfExported(symbol).ValueDeclaration if declaration != nil && (ast.IsBindingElement(declaration) || ast.IsParameter(declaration)) && f.reference == declaration.Parent && declaration.Initializer() == nil && !hasDotDotDotToken(declaration) { return declaration } diff --git a/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types b/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types index b1c5ddb783..e52d955c98 100644 --- a/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types +++ b/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types @@ -49,5 +49,5 @@ if (discriminator2) { >discriminator2 : boolean value2; ->value2 : string | null | undefined +>value2 : string } diff --git a/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types.diff b/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types.diff deleted file mode 100644 index aad1a04386..0000000000 --- a/testdata/baselines/reference/submodule/conformance/dependentDestructuredVariablesWithExport.types.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.dependentDestructuredVariablesWithExport.types -+++ new.dependentDestructuredVariablesWithExport.types -@@= skipped -48, +48 lines =@@ - >discriminator2 : boolean - - value2; -->value2 : string -+>value2 : string | null | undefined - } \ No newline at end of file