Skip to content

[Errors] Shorter: Neither type X nor type Y is assignable to the other #97

Description

@mhegazy
// Function call whose argument is a 1 arg generic function call with explicit type arguments
function fn1<T>(t: T) { }
function fn2(t: any) { }

fn1(fn2<string>(4)); // Error

var a: any;
var s: string;

// Type assertion of non - unary expression
var a = <any>"" + 4;
var s = "" + <any>4;

class SomeBase {
    private p;
}
class SomeDerived extends SomeBase {
    private x;
}
class SomeOther {
    private q;
}

// Type assertion should check for assignability in either direction
var someBase = new SomeBase();
var someDerived = new SomeDerived();
var someOther = new SomeOther();

someBase = <SomeBase>someDerived;
someBase = <SomeBase>someBase;
someBase = <SomeBase>someOther; // Error

someDerived = <SomeDerived>someDerived;
someDerived = <SomeDerived>someBase;
someDerived = <SomeDerived>someOther; // Error

someOther = <SomeOther>someDerived; // Error
someOther = <SomeOther>someBase; // Error
someOther = <SomeOther>someOther;

Expected:

// Function call whose argument is a 1 arg generic function call with explicit type arguments
function fn1(t: T) { }
function fn2(t: any) { }

fn1(fn2<string>(4)); // Error

!!! Could not select overload for 'call' expression.

var a: any;
var s: string;

// Type assertion of non - unary expression
var a = <any>"" + 4;
var s = "" + <any>4;

class SomeBase {
    private p;
}
class SomeDerived extends SomeBase {
    private x;
}
class SomeOther {
    private q;
}

// Type assertion should check for assignability in either direction
var someBase = new SomeBase();
var someDerived = new SomeDerived();
var someOther = new SomeOther();

someBase = <SomeBase>someDerived;
someBase = <SomeBase>someBase;
someBase = <SomeBase>someOther; // Error

!!! Neither type 'SomeOther' nor type 'SomeBase' is assignable to the other:
!!! Type 'SomeOther' is missing property 'p' from type 'SomeBase'.
!!! Type 'SomeBase' is missing property 'q' from type 'SomeOther'.

someDerived = <SomeDerived>someDerived;
someDerived = <SomeDerived>someBase;
someDerived = <SomeDerived>someOther; // Error

!!! Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other:
!!! Type 'SomeOther' is missing property 'x' from type 'SomeDerived'.
!!! Type 'SomeDerived' is missing property 'q' from type 'SomeOther'.

someOther = <SomeOther>someDerived; // Error

!!! Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other:
!!! Type 'SomeDerived' is missing property 'q' from type 'SomeOther'.
!!! Type 'SomeOther' is missing property 'x' from type 'SomeDerived'.
someOther = someBase; // Error
!!! Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other:
!!! Type 'SomeBase' is missing property 'q' from type 'SomeOther'.
!!! Type 'SomeOther' is missing property 'p' from type 'SomeBase'.
someOther = someOther;

Actual:

// Function call whose argument is a 1 arg generic function call with explicit type arguments
function fn1(t: T) { }
function fn2(t: any) { }

fn1(fn2<string>(4)); // Error

!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.

var a: any;
var s: string;

// Type assertion of non - unary expression
var a = <any>"" + 4;
var s = "" + <any>4;

class SomeBase {
    private p;
}
class SomeDerived extends SomeBase {
    private x;
}
class SomeOther {
    private q;
}

// Type assertion should check for assignability in either direction
var someBase = new SomeBase();
var someDerived = new SomeDerived();
var someOther = new SomeOther();

someBase = <SomeBase>someDerived;
someBase = <SomeBase>someBase;
someBase = <SomeBase>someOther; // Error

!!! Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other.

someDerived = <SomeDerived>someDerived;
someDerived = <SomeDerived>someBase;
someDerived = <SomeDerived>someOther; // Error

!!! Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other.

someOther = <SomeOther>someDerived; // Error

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions