Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4330,8 +4330,8 @@ module ts {
var targetType = getTypeFromTypeNode(node.type);
if (fullTypeCheck && targetType !== unknownType) {
var widenedType = getWidenedType(exprType);
if (!(isTypeAssignableTo(exprType, targetType) || isTypeAssignableTo(targetType, widenedType))) {
checkTypeAssignableTo(targetType, widenedType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
if (!(isTypeAssignableTo(targetType, widenedType))) {
checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
}
}
return targetType;
Expand Down
5 changes: 3 additions & 2 deletions tests/baselines/reference/arrayCast.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// has type { foo: string }[], which is not assignable to { id: number }[].
<{ id: number; }[]>[{ foo: "s" }];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Neither type '{ id: number; }[]' nor type '{ foo: string; }[]' is assignable to the other:
!!! Type '{ id: number; }' is not assignable to type '{ foo: string; }'.
!!! Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other:
!!! Type '{ foo: string; }' is not assignable to type '{ id: number; }':
!!! Property 'id' is missing in type '{ foo: string; }'.

// Should succeed, as the {} element causes the type of the array to be {}[]
<{ id: number; }[]>[{ foo: "s" }, {}];
3 changes: 2 additions & 1 deletion tests/baselines/reference/contextualTyping39.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
==== tests/cases/compiler/contextualTyping39.ts (1 errors) ====
var foo = <{ (): number; }> function() { return "err"; };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Neither type '() => number' nor type '() => string' is assignable to the other.
!!! Neither type '() => string' nor type '() => number' is assignable to the other:
!!! Type 'string' is not assignable to type 'number'.
3 changes: 2 additions & 1 deletion tests/baselines/reference/contextualTyping41.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
==== tests/cases/compiler/contextualTyping41.ts (1 errors) ====
var foo = <{():number; (i:number):number; }> (function(){return "err";});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Neither type '{ (): number; (i: number): number; }' nor type '() => string' is assignable to the other.
!!! Neither type '() => string' nor type '{ (): number; (i: number): number; }' is assignable to the other:
!!! Type 'string' is not assignable to type 'number'.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Contextually type the default arg with the type annotation
var f3 = function (a: (s: string) => any = (s) => <number>s) { };
~~~~~~~~~
!!! Neither type 'number' nor type 'string' is assignable to the other.
!!! Neither type 'string' nor type 'number' is assignable to the other.

// Type check using the function's contextual type
var f4: (a: number) => void = function (a = "") { };
Expand All @@ -32,7 +32,7 @@
// Contextually type the default arg using the function's contextual type
var f5: (a: (s: string) => any) => void = function (a = s => <number>s) { };
~~~~~~~~~
!!! Neither type 'number' nor type 'string' is assignable to the other.
!!! Neither type 'string' nor type 'number' is assignable to the other.

// Instantiated module
module T { }
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/fuzzy.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
worksToo():R {
return <R>({ oneI: this });
~~~~~~~~~~~~~~~~~~~
!!! Neither type 'R' nor type '{ oneI: C; }' is assignable to the other.
!!! Neither type '{ oneI: C; }' nor type 'R' is assignable to the other:
!!! Property 'anything' is missing in type '{ oneI: C; }'.
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/baselines/reference/genericTypeAssertions1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
!!! Type 'A<A<number>>' is not assignable to type 'A<number>':
!!! Type 'A<number>' is not assignable to type 'number'.
~~~~~~~~~~~~~~~~~
!!! Neither type 'A<A<number>>' nor type 'A<number>' is assignable to the other:
!!! Type 'A<number>' is not assignable to type 'number'.
!!! Neither type 'A<number>' nor type 'A<A<number>>' is assignable to the other:
!!! Type 'number' is not assignable to type 'A<number>':
!!! Property 'foo' is missing in type 'Number'.
3 changes: 2 additions & 1 deletion tests/baselines/reference/genericTypeAssertions2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
var r4: A<number> = <A<number>>new A();
var r5: A<number> = <A<number>>[]; // error
~~~~~~~~~~~~~
!!! Neither type 'A<number>' nor type 'any[]' is assignable to the other.
!!! Neither type 'undefined[]' nor type 'A<number>' is assignable to the other:
!!! Property 'foo' is missing in type 'undefined[]'.
4 changes: 2 additions & 2 deletions tests/baselines/reference/genericTypeAssertions4.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
y = <T>a;
y = <T>b; // error: cannot convert B to T
~~~~
!!! Neither type 'T' nor type 'B' is assignable to the other.
!!! Neither type 'B' nor type 'T' is assignable to the other.
y = <T>c; // error: cannot convert C to T
~~~~
!!! Neither type 'T' nor type 'C' is assignable to the other.
!!! Neither type 'C' nor type 'T' is assignable to the other.
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/genericTypeAssertions5.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
y = <T>a;
y = <T>b; // error: cannot convert B to T
~~~~
!!! Neither type 'T' nor type 'B' is assignable to the other.
!!! Neither type 'B' nor type 'T' is assignable to the other.
y = <T>c; // error: cannot convert C to T
~~~~
!!! Neither type 'T' nor type 'C' is assignable to the other.
!!! Neither type 'C' nor type 'T' is assignable to the other.
}
6 changes: 3 additions & 3 deletions tests/baselines/reference/genericTypeAssertions6.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
f(x: T, y: U) {
x = <T>y;
~~~~
!!! Neither type 'T' nor type 'U' is assignable to the other.
!!! Neither type 'U' nor type 'T' is assignable to the other.
y = <U>x;
~~~~
!!! Neither type 'U' nor type 'T' is assignable to the other.
!!! Neither type 'T' nor type 'U' is assignable to the other.
}
}

Expand All @@ -23,7 +23,7 @@
var d = <U>new Date();
var e = <T><U>new Date();
~~~~~~~~~~~~~~~~
!!! Neither type 'T' nor type 'U' is assignable to the other.
!!! Neither type 'U' nor type 'T' is assignable to the other.
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/intTypeCheck.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
var obj69: i7 = new obj66;
var obj70: i7 = <i7>new Base;
~~~~~~~~~~~~
!!! Neither type 'i7' nor type 'Base' is assignable to the other.
!!! Neither type 'Base' nor type 'i7' is assignable to the other.
var obj71: i7 = null;
var obj72: i7 = function () { };
~~~~~
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/literals-negative.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var s = <string>(null);
var b = <boolean>(n);
~~~~~~~~~~~~
!!! Neither type 'boolean' nor type 'number' is assignable to the other.
!!! Neither type 'number' nor type 'boolean' is assignable to the other.

function isVoid() : void { }

Expand Down
10 changes: 6 additions & 4 deletions tests/baselines/reference/typeAssertions.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@
someBase = <SomeBase>someBase;
someBase = <SomeBase>someOther; // Error
~~~~~~~~~~~~~~~~~~~
!!! Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other.
!!! Neither type 'SomeOther' nor type 'SomeBase' is assignable to the other:
!!! Property 'p' is missing in type 'SomeOther'.

someDerived = <SomeDerived>someDerived;
someDerived = <SomeDerived>someBase;
someDerived = <SomeDerived>someOther; // Error
~~~~~~~~~~~~~~~~~~~~~~
!!! Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other.
!!! Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other:
!!! Property 'x' is missing in type 'SomeOther'.

someOther = <SomeOther>someDerived; // Error
~~~~~~~~~~~~~~~~~~~~~~
!!! Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other.
!!! Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other.
someOther = <SomeOther>someBase; // Error
~~~~~~~~~~~~~~~~~~~
!!! Neither type 'SomeOther' nor type 'SomeBase' is assignable to the other.
!!! Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other.
someOther = <SomeOther>someOther;


Expand Down