-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Recursive type with index signature issues spurious error #1889
Comments
interface Foo {
[x: string]: number|Foo;
}
interface Bar extends Foo {
// OK
bar: {
num: number;
[x: string]: number|Foo
};
} |
@RyanCavanaugh Has an issue related to implicit indexer typing already been opened somewhere? Would be nice to just be able to specify |
The indexing type can also be |
Yes, but it doesn't look like TS actually enforces the type you specify (i.e. |
Numbers are converted to strings during indexing operations, so it's valid to specify a number as the indexing expression. The converse is not the case -- if you declare only a number indexer, you can't index by a string without producing an implicit |
Hi,
TS:1.4
The compiler issues an error on property
bar
below:My understanding of this is "any type that extends
Foo
is permitted to have a property that is either a number or an object that is indexable by string to produce a number or..(and so on) ".The latter case is clearly true for
{num: number}
and yet the compiler issues an error.The text was updated successfully, but these errors were encountered: