Skip to content

Commit 0432954

Browse files
committed
Small fix in getIsContextSensitiveAssignmentOrContextType
Test that `parentSymbol.valueDeclaration` exists. Fixes microsoft#38532
1 parent 8231519 commit 0432954

6 files changed

+66
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22589,7 +22589,7 @@ namespace ts {
2258922589
const id = lhs.expression;
2259022590
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, undefined, id.escapedText, /*isUse*/ true);
2259122591
if (parentSymbol) {
22592-
const annotated = getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
22592+
const annotated = parentSymbol.valueDeclaration && getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
2259322593
if (annotated) {
2259422594
const nameStr = getElementOrPropertyAccessName(lhs);
2259522595
if (nameStr !== undefined) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts(2,17): error TS2307: Cannot find module 'blah' or its corresponding type declarations.
2+
3+
4+
==== tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts (1 errors) ====
5+
// GH #38532
6+
import Foo from "blah";
7+
~~~~~~
8+
!!! error TS2307: Cannot find module 'blah' or its corresponding type declarations.
9+
10+
export function Foo() { }
11+
12+
Foo.bar = () => { };
13+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [expandoFunctionContextualTypesNoValue.ts]
2+
// GH #38532
3+
import Foo from "blah";
4+
5+
export function Foo() { }
6+
7+
Foo.bar = () => { };
8+
9+
10+
//// [expandoFunctionContextualTypesNoValue.js]
11+
"use strict";
12+
exports.__esModule = true;
13+
exports.Foo = void 0;
14+
// GH #38532
15+
var blah_1 = require("blah");
16+
function Foo() { }
17+
exports.Foo = Foo;
18+
blah_1["default"].bar = function () { };
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts ===
2+
// GH #38532
3+
import Foo from "blah";
4+
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesNoValue.ts, 1, 23), Decl(expandoFunctionContextualTypesNoValue.ts, 1, 6))
5+
6+
export function Foo() { }
7+
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesNoValue.ts, 1, 23), Decl(expandoFunctionContextualTypesNoValue.ts, 3, 25))
8+
9+
Foo.bar = () => { };
10+
>Foo.bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesNoValue.ts, 3, 25))
11+
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesNoValue.ts, 1, 23), Decl(expandoFunctionContextualTypesNoValue.ts, 1, 6))
12+
>bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesNoValue.ts, 3, 25))
13+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts ===
2+
// GH #38532
3+
import Foo from "blah";
4+
>Foo : any
5+
6+
export function Foo() { }
7+
>Foo : typeof import("tests/cases/compiler/expandoFunctionContextualTypesNoValue").Foo
8+
9+
Foo.bar = () => { };
10+
>Foo.bar = () => { } : () => void
11+
>Foo.bar : () => void
12+
>Foo : typeof import("tests/cases/compiler/expandoFunctionContextualTypesNoValue").Foo
13+
>bar : () => void
14+
>() => { } : () => void
15+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// GH #38532
2+
import Foo from "blah";
3+
4+
export function Foo() { }
5+
6+
Foo.bar = () => { };

0 commit comments

Comments
 (0)