I noticed that when creating an interface, if you then create an object of that type, you must include all the properties:
interface twoProps {
first: number;
// second: string;
}
const a: twoProps = {
first: 5,
second: 'fgfg'
}
This will show an error, because second shouldn't be a part of a.
However when creating a function with an argument of that interface, you can pass an object that doesn't necessarily have all the properties:
interface twoProps {
first: number;
// second: string;
}
const a = {
first: 5,
second: 'fgfg'
}
function run (a: twoProps): void {
console.log('running')
}
run(a)
Here we won't get an error. What is the reasoning behind this difference?