for...in
+if...hasOwnProperty
is typed differently from Object.keys()
#38437
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
THIS IS NOT THE USUAL
Object.keys
TYPING "BUG".TypeScript Version: 3.8.3
Search Terms: Object.keys
Code
Issue
The two
for
-loops above should be functionally identical (with the exception that the secondfor
-loop is less-efficient.) Accordingly,key
should have the same type in each.However, in the former,
key
is astring
, per the logic given by @RyanCavanaugh on Stack Overflow; while, in the latter,key
isExtract<keyof T, string>
. Correct me if I'm understanding this wrong; but ifkeyof
isn't safe in the former, it seems like it wouldn't be safe in the latter, either.Related Issues:
#12253, #30314, #13254. #30228, #28899, #28284, #26901, #30749, #31087, #32321, #34498, #35145.
The text was updated successfully, but these errors were encountered: