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.
Never and unknown
Safe property access
Report a typo
Sample Input 1:
Sample Output 1:
This is a prop
undefinedWrite a program in TypeScript
// write your code here
function safeAccess() {
}
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.