This project is read-only.

Property access using bracket notation allowed on any object?

Topics: Language Specification
Jun 15, 2013 at 11:34 PM
Section 4.10 of the spec states that accessing a property of an object type through bracket notation is only allowed if the object type has index signatures. At least that's how I read it. Feel free to correct me if I'm wrong. Now, based on this I expect the following code to be incorrect:
interface IFoo { }
var x: IFoo = {};
var y = x[0]; // no index signature in IFoo, so this shouldn't work, right?
But I get no error. If I add an index signature that is incompatible with the property access, I get an error:
interface IFoo {
  [s: string]: string;

var x: IFoo = {};
var y = x[0]; // <-- test.ts(6,8): Illegal property access
Is allowing arbitrary property access in the absence of index signatures expected behavior, or is it a bug? I'm using tsc version 0.8.3.