Let's say I define an interface like this
interface User {
name: string;
address?: SomeObject;
}
Later in the code I definitely define it through some dynamic process. Because I can't/don't want to initially define it with a dummy object.
Then I want to use it like this in a function
const foo=(name:string, address: SomeObject)=>{
console.log(address);
}
If I use it like this
foo(user.name, user.address)
I will get that param2 is possibly undefined.
If I do it like this
const foo=(name:string, address?: SomeObject)=>{
console.log(address);
}
Then I can call the function but I would have to check inside the function body whether address is defined.
What I want to know if I can to is something like this
const foo=(name:string, address: SomeObject)=>{
console.log(address);
}
foo(user.name, user.address!) //where ! is a made up operator that says this object is definitely defined.
tldr: I want to know if there is a way to say to TS that this possibly undefined value is certainly defined by this time of execution.