Closed
Description
openedon Dec 1, 2016
It doesn't make much sense to forbid property access (o.unknown
) syntax on a type with a string index signature, but allow element access syntax (o['unknown']
).
Note that this should only apply to types with an explicit string index signature — element access is currently allowed on any type if you don't pass --noImplicitAny
, but this should not be true for property access.
Given
type Flags = {
aLongName: boolean;
anotherReallyLongOne: number;
someOtherOnes: boolean;
[other: string]: number | boolean;
}
Expected behavior:
function f(flags: Flags) {
flags.aLongName; // ok
flags.anUnknownName; // ok
flags.aLongname; // ok, but misspelled
flags['aLongName']; // ok
flags['anUnknownName']; // ok
flags['aLongname']; // ok, but misspelled
}
Actual behavior:
function f(flags: Flags) {
flags.aLongName; // ok
flags.anUnknownName; // error, unknown
flags.aLongname; // error, misspelled
flags['aLongName']; // ok
flags['anUnknownName']; // ok
flags['aLongname']; // ok, but misspelled
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment