I'm struggling to find the distinction between two similar lines of code due to uncertainty about what they are called. Consider the scenario where the following interface is defined:
interface Person {
name: string;
age: number;
}
What exactly separates the following pieces of code?
const foo: Person = getPerson(data);
and
const foo = getPerson(data) as Person;
It appears that both lines inform TypeScript that foo
is a Person
. Is there a significant difference between the two, or is it simply a matter of personal preference?