How can I use a property of an interface as a type for a variable in typescript ??
Here I want to access the property: string
type and use it as a type for a variable but I cannot access it.
interface foo {
bar?: {
baz: {
property: string;
};
};
}
function f(input: foo['bar']['baz']['property']) {
console.log(input);
}
I was trying to find some optional chaining rule for this, but none of the JavaScript chaining methods worked here.
Error
Property 'baz' does not exist on type '{ baz: { property: string; } ' | undefined