-
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
Object.keys / Object.entries not type checking argument #35145
Comments
Since the function definition for Observe:
|
Everything except tl;dr: |
Makes sense, perhaps the expected parameter type for P.S: Re the link by @Validark above, is there a reason why the |
I think primitives are still assignable to that. It would have to be |
@rohitf In general, With regards to Object.keys/Object.entries: I don't know what decisions were made or why. |
Technically, it's valid to pass a non-object literal to Object.keys(0); // []
Object.keys('a'); // ['0'] |
@resynth1943 wow didn't know that, looks like it's definitely possible but generally not safe / intended behavior. In that case, a warning would likely be better than an error (since it is valid JS). |
There is no distinction between warnings and errors in TS. Sometimes I wish there was. 🙁 |
"not safe" / "not intended" is in the eye of the beholder. If In any case, |
TypeScript Version: 3.7.2
Search Terms:
keys
entries
Code
Note: The same issue occurs with
Object.entries
Expected behavior:
TypeScript error since number and string are not valid parameter types for
Object.keys(object)
.Actual behavior:
No error/warning.
Playground Link:
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=11&pc=2#code/PTAEHsCMCtQSwM6gIagHYFcC2kCmAnAWACgAbXAFwhgC51s99QBeUAJgGYSAzcJgCnJUA1rgCeEbqADyMXAGMKAOlFiE-KNACUWgN4lQh0PPBoE4cktLgA5v1VaSAXxIkQ1aAEZ4SVAgr4cGg2JEIebHT+gcEsoABEABa4pNZxPHyggpSgqpIycooq4uqabDr6xEbGpuaW1nYOzkA
Related Issues:
N/A
The text was updated successfully, but these errors were encountered: