Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison operator on types with indexer signatures returning object types #401

Closed
danquirk opened this issue Aug 8, 2014 · 1 comment · May be fixed by Woodpile37/TypeScript#10
Closed
Labels
Bug A bug in TypeScript By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@danquirk
Copy link
Member

danquirk commented Aug 8, 2014

class Base {
        public a: string;
}

class Derived extends Base {
        public b: string;
}



var a4: { [index: number]: Base };
var b4: { [index: string]: Derived }; 

var r1a1 = a4 < b4;

Actual: no error
Expected: Operator '<' cannot be applied to types '{ [x: number]: Base; }' and '{ [x: string]: Derived; }'.

The current behavior matches the old compiler because fixing this would be a breaking change we aligned them. Worth considering whether to just take the break since it's unlikely someone would take an intentional dependeny on this undefined behavior.

@sophiajt sophiajt added this to the TypeScript 1.2 milestone Aug 11, 2014
@ahejlsberg
Copy link
Member

This isn't a bug. The type of b4 is a subtype of the type of a4 according to the following rule in section 3.8.3 of the spec (note emphasis):

  • M is a numeric index signature of type U and S’ contains a _string_ or numeric index signature of a type that is a subtype of U.

Both compilers implement this correctly.

@RyanCavanaugh RyanCavanaugh added By Design Deprecated - use "Working as Intended" or "Design Limitation" instead and removed Breaking Change Would introduce errors in existing code labels Sep 8, 2014
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants