-
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
Number index signature doesn't work with Readonly generic #17857
Comments
|
In addition to what @olegdunkan stated, Consider rewriting the example function as function foobar(): void {
const x = Object.freeze({
0: 'asdf',
1: 'fdsa',
[-1]: 'dddd',
});
const y = Object.freeze({
0: 'qwer',
1: 'rewq',
[-1]: 'eeee',
});
const z: string = x[0] + y[0];
} |
@olegdunkan
P.S. I think it should be separate issue, but I don't get any error when I do |
Declaration of type Readonly<T> = {
readonly [P in keyof T]: T[P];
}; The type of Then we can assume that in the case of a number index signature
|
Oh, it was related to mapped type's operation. |
TypeScript Version: 2.4.2
Code
Expected behavior:
No Error
Actual behavior:
Shows error
Element implicitly has an 'any' type because type 'Readonly<{ [n: number]: string; }>' has no index signature.
forx[0]
.The text was updated successfully, but these errors were encountered: