Write a TypeScript function called safeAccess that takes an object of type unknown and a property name as a string. The function must safely access the property of the object and return its value if it exists. If the property doesn't exist or the input object is not an object, the function must return undefined. Fill in the blanks to complete the program.
Never and unknown
Safe property access
Report a typo
Fill in the gaps with the relevant elements
function safeAccess(obj: , propName: ): {
if (typeof obj === && obj !== ) {
return (obj as {[key: string]: unknown})[];
}
return ;
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.