-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Functions are compatible with ArrayLike<any> #18757
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
Comments
Essentially, this issue is a question: how are index signatures used when determining compatibility? With functions, the index signature appears to be considered only if the signature's value type is not // OK:
const a = () => {};
const b: { [n: number]: any } = a;
// ERROR: Index signature is missing in type '() => void'.
const c = () => {};
const d: { [n: number]: string } = c; However, with interfaces, the index signature appears to be considered only if it is present: // OK:
const e: { length: number } = { length: 0 };
const f: { [n: number]: any } = e;
// OK:
const g: { length: number } = { length: 0 };
const h: { [n: number]: string } = g;
// ERROR: Index signatures are incompatible.
const i: { length: number, [n: number]: number } = { length: 0 };
const j: { [n: number]: string } = i; Searching has not yielded any answer as to what the expected behaviour is. And the considering of functions to be compatible with |
The real culprit is the We can explore backing out the special rule about |
Thanks. I'd guessed that there's an ad-hoc rule regarding I'm curious as to why the seemingly-similar interface scenario does not effect an error: const g: { length: number } = { length: 0 };
const h: { [n: number]: string } = g; Is there an explanation for what appears to be differing behaviour? |
@sandersn we'd like to see what happens in RWC if we restrict the " |
Any progress on this? We're still hitting it |
TypeScript Version: 2.5.2
Code
See this TypeScript Playground example.
Expected behavior:
I'd have expected an error to be effected.
Actual behavior:
No error is effected if the type
ArrayLike<any>
is specified. It seems the absence of an index signature is not a consideration in this situation.If the
any
is changed to, say,string
an error is effected:The text was updated successfully, but these errors were encountered: