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:
commit
6b4a3b2bbb
|
@ -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(
|
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,
|
Diagnostics.The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1,
|
||||||
propertyName && !(nameType.flags & TypeFlags.UniqueESSymbol) ? unescapeLeadingUnderscores(propertyName) : typeToString(nameType),
|
propertyName && !(nameType.flags & TypeFlags.UniqueESSymbol) ? unescapeLeadingUnderscores(propertyName) : typeToString(nameType),
|
||||||
typeToString(target)
|
typeToString(target)
|
||||||
|
|
|
@ -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 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
|
||||||
Type 'Ref<string>' is not assignable to type 'Ref<number>'.
|
Type 'Ref<string>' is not assignable to type 'Ref<number>'.
|
||||||
Type 'string' is not assignable to type '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
|
// Repro for #5712
|
||||||
|
|
||||||
interface Ref<T> {
|
interface Ref<T> {
|
||||||
|
@ -23,3 +24,12 @@ tests/cases/compiler/errorElaboration.ts(12,5): error TS2345: Argument of type '
|
||||||
!!! error TS2345: Type 'Ref<string>' is not assignable to type 'Ref<number>'.
|
!!! error TS2345: Type 'Ref<string>' is not assignable to type 'Ref<number>'.
|
||||||
!!! error TS2345: Type 'string' is not assignable to type '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"; }'
|
||||||
|
}
|
||||||
|
|
|
@ -12,8 +12,18 @@ declare function foo(x: () => Container<Ref<number>>): void;
|
||||||
let a: () => Container<Ref<string>>;
|
let a: () => Container<Ref<string>>;
|
||||||
foo(a);
|
foo(a);
|
||||||
|
|
||||||
|
// Repro for #25498
|
||||||
|
|
||||||
|
function test(): {[A in "foo"]: A} {
|
||||||
|
return {foo: "bar"};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//// [errorElaboration.js]
|
//// [errorElaboration.js]
|
||||||
// Repro for #5712
|
// Repro for #5712
|
||||||
var a;
|
var a;
|
||||||
foo(a);
|
foo(a);
|
||||||
|
// Repro for #25498
|
||||||
|
function test() {
|
||||||
|
return { foo: "bar" };
|
||||||
|
}
|
||||||
|
|
|
@ -38,3 +38,14 @@ foo(a);
|
||||||
>foo : Symbol(foo, Decl(errorElaboration.ts, 8, 1))
|
>foo : Symbol(foo, Decl(errorElaboration.ts, 8, 1))
|
||||||
>a : Symbol(a, Decl(errorElaboration.ts, 10, 3))
|
>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))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,3 +39,16 @@ foo(a);
|
||||||
>foo : (x: () => Container<Ref<number>>) => void
|
>foo : (x: () => Container<Ref<number>>) => void
|
||||||
>a : () => Container<Ref<string>>
|
>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"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,9 @@ interface Container<T> {
|
||||||
declare function foo(x: () => Container<Ref<number>>): void;
|
declare function foo(x: () => Container<Ref<number>>): void;
|
||||||
let a: () => Container<Ref<string>>;
|
let a: () => Container<Ref<string>>;
|
||||||
foo(a);
|
foo(a);
|
||||||
|
|
||||||
|
// Repro for #25498
|
||||||
|
|
||||||
|
function test(): {[A in "foo"]: A} {
|
||||||
|
return {foo: "bar"};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue