Is there a way to use an interface property as a variable type in TypeScript?
I need to access the property: string
type and use it as a variable type, but I'm having trouble accessing it.
interface foo {
bar?: {
baz: {
property: string;
};
};
}
function f(input: foo['bar']['baz']['property']) {
console.log(input);
}
I've tried looking into optional chaining rules for this issue, but none of the JavaScript chain methods seem to work here.
Error
Property 'baz' does not exist on type '{ baz: { property: string; } ' | undefined