The Javascript type system is amazing as always, this error was due to the fact that typeof null === 'object' returns true, combined with the fact that any in Typescript does not do type-narrowing very well. Switching any to unknown made the mistake more apparent, now warning that obj could be either object | null which gave a type error in Object.keys.
A lesson here is that unknown can be more useful in cases like this instead of using any explicitly when you dont know the type.
Description
The Javascript type system is amazing as always, this error was due to the fact that
typeof null === 'object'
returns true, combined with the fact thatany
in Typescript does not do type-narrowing very well. Switchingany
tounknown
made the mistake more apparent, now warning thatobj
could be eitherobject | null
which gave a type error inObject.keys
.A lesson here is that
unknown
can be more useful in cases like this instead of usingany
explicitly when you dont know the type.Related Issue(s)
Verification/QA
kind/*
label to this PR for proper release notes grouping