Merge pull request #25500 from mattmccutchen/issue-25498

Fix crash in elaborateElementwise when the target property is known but it doesn't have a declaration (e.g., in a mapped type).
This commit is contained in:
Mohamed Hegazy 2018-07-09 15:35:35 -07:00 committed by GitHub
commit 6b4a3b2bbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 3 deletions

View file

@ -10367,9 +10367,9 @@ namespace ts {
}
}
if (!issuedElaboration && (length(targetProp && targetProp.declarations) || length(target.symbol && target.symbol.declarations))) {
if (!issuedElaboration && (targetProp && length(targetProp.declarations) || target.symbol && length(target.symbol.declarations))) {
addRelatedInfo(reportedDiag, createDiagnosticForNode(
targetProp ? targetProp.declarations[0] : target.symbol.declarations[0],
targetProp && length(targetProp.declarations) ? targetProp.declarations[0] : target.symbol.declarations[0],
Diagnostics.The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1,
propertyName && !(nameType.flags & TypeFlags.UniqueESSymbol) ? unescapeLeadingUnderscores(propertyName) : typeToString(nameType),
typeToString(target)

View file

@ -2,9 +2,10 @@ tests/cases/compiler/errorElaboration.ts(12,5): error TS2345: Argument of type '
Type 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
Type 'Ref<string>' is not assignable to type 'Ref<number>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/errorElaboration.ts(17,11): error TS2322: Type '"bar"' is not assignable to type '"foo"'.
==== tests/cases/compiler/errorElaboration.ts (1 errors) ====
==== tests/cases/compiler/errorElaboration.ts (2 errors) ====
// Repro for #5712
interface Ref<T> {
@ -22,4 +23,13 @@ tests/cases/compiler/errorElaboration.ts(12,5): error TS2345: Argument of type '
!!! error TS2345: Type 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
!!! error TS2345: Type 'Ref<string>' is not assignable to type 'Ref<number>'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
// Repro for #25498
function test(): {[A in "foo"]: A} {
return {foo: "bar"};
~~~
!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'.
!!! related TS6500 tests/cases/compiler/errorElaboration.ts:16:18: The expected type comes from property 'foo' which is declared here on type '{ foo: "foo"; }'
}

View file

@ -11,9 +11,19 @@ interface Container<T> {
declare function foo(x: () => Container<Ref<number>>): void;
let a: () => Container<Ref<string>>;
foo(a);
// Repro for #25498
function test(): {[A in "foo"]: A} {
return {foo: "bar"};
}
//// [errorElaboration.js]
// Repro for #5712
var a;
foo(a);
// Repro for #25498
function test() {
return { foo: "bar" };
}

View file

@ -38,3 +38,14 @@ foo(a);
>foo : Symbol(foo, Decl(errorElaboration.ts, 8, 1))
>a : Symbol(a, Decl(errorElaboration.ts, 10, 3))
// Repro for #25498
function test(): {[A in "foo"]: A} {
>test : Symbol(test, Decl(errorElaboration.ts, 11, 7))
>A : Symbol(A, Decl(errorElaboration.ts, 15, 19))
>A : Symbol(A, Decl(errorElaboration.ts, 15, 19))
return {foo: "bar"};
>foo : Symbol(foo, Decl(errorElaboration.ts, 16, 10))
}

View file

@ -39,3 +39,16 @@ foo(a);
>foo : (x: () => Container<Ref<number>>) => void
>a : () => Container<Ref<string>>
// Repro for #25498
function test(): {[A in "foo"]: A} {
>test : () => { foo: "foo"; }
>A : A
>A : A
return {foo: "bar"};
>{foo: "bar"} : { foo: "bar"; }
>foo : "bar"
>"bar" : "bar"
}

View file

@ -10,3 +10,9 @@ interface Container<T> {
declare function foo(x: () => Container<Ref<number>>): void;
let a: () => Container<Ref<string>>;
foo(a);
// Repro for #25498
function test(): {[A in "foo"]: A} {
return {foo: "bar"};
}