Small fix in getIsContextSensitiveAssignmentOrContextType

Test that `parentSymbol.valueDeclaration` exists.

Fixes #38532
This commit is contained in:
Eli Barzilay 2020-06-12 16:57:27 -04:00
parent 8231519b85
commit 0432954f2d
6 changed files with 66 additions and 1 deletions

View File

@ -22589,7 +22589,7 @@ namespace ts {
const id = lhs.expression;
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, undefined, id.escapedText, /*isUse*/ true);
if (parentSymbol) {
const annotated = getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
const annotated = parentSymbol.valueDeclaration && getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
if (annotated) {
const nameStr = getElementOrPropertyAccessName(lhs);
if (nameStr !== undefined) {

View File

@ -0,0 +1,13 @@
tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts(2,17): error TS2307: Cannot find module 'blah' or its corresponding type declarations.
==== tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts (1 errors) ====
// GH #38532
import Foo from "blah";
~~~~~~
!!! error TS2307: Cannot find module 'blah' or its corresponding type declarations.
export function Foo() { }
Foo.bar = () => { };

View File

@ -0,0 +1,18 @@
//// [expandoFunctionContextualTypesNoValue.ts]
// GH #38532
import Foo from "blah";
export function Foo() { }
Foo.bar = () => { };
//// [expandoFunctionContextualTypesNoValue.js]
"use strict";
exports.__esModule = true;
exports.Foo = void 0;
// GH #38532
var blah_1 = require("blah");
function Foo() { }
exports.Foo = Foo;
blah_1["default"].bar = function () { };

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts ===
// GH #38532
import Foo from "blah";
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesNoValue.ts, 1, 23), Decl(expandoFunctionContextualTypesNoValue.ts, 1, 6))
export function Foo() { }
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesNoValue.ts, 1, 23), Decl(expandoFunctionContextualTypesNoValue.ts, 3, 25))
Foo.bar = () => { };
>Foo.bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesNoValue.ts, 3, 25))
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesNoValue.ts, 1, 23), Decl(expandoFunctionContextualTypesNoValue.ts, 1, 6))
>bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesNoValue.ts, 3, 25))

View File

@ -0,0 +1,15 @@
=== tests/cases/compiler/expandoFunctionContextualTypesNoValue.ts ===
// GH #38532
import Foo from "blah";
>Foo : any
export function Foo() { }
>Foo : typeof import("tests/cases/compiler/expandoFunctionContextualTypesNoValue").Foo
Foo.bar = () => { };
>Foo.bar = () => { } : () => void
>Foo.bar : () => void
>Foo : typeof import("tests/cases/compiler/expandoFunctionContextualTypesNoValue").Foo
>bar : () => void
>() => { } : () => void

View File

@ -0,0 +1,6 @@
// GH #38532
import Foo from "blah";
export function Foo() { }
Foo.bar = () => { };