-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
keyof {[n: number]: any} should be string, not never #22105
Comments
cc/ @sandersn |
I'm inclined to think you're right that |
On second thought, it wouldn't work to change this behavior since array and string types have numeric index signatures and all of a sudden would see their |
In practical terms, is there any use case for applying It is useful that string and arrays have numeric indexers so expressions like |
BTW why does |
Cause implementation wise we treat |
A related issue from @rhys-vdw: const numbers: Readonly<{ [id: number]: number }> = { 0: 0 };
const values = Object.values(numbers); // Expected number[], got {}[] |
Is this related, or I should file it as separate issue? |
With #23592, |
TypeScript Version: 2.8.0-dev.20180216
Search Terms:
Code
Expected behavior:
N2
andN3
should bestring
.Actual behavior:
N2
isnever
andN3
is"42"
.Related Issues:
#13715 seems related but isn't really - it is asking for
keyof T
to allow numbers.#22042 has an example showing how
lodash
typings incorrectly producenever
for objects that have numeric indexers.Discussion:
In JavaScript, both string and numeric keys end up effectively being string keys.
keyof
uniformly handles string keys, numeric keys, and string indexers. Why does it ignore numeric indexers?The text was updated successfully, but these errors were encountered: