Within my codebase, there exists an interface:
export interface IFieldValue {
name: string;
value: string;
}
This interface is implemented by a class named Person:
class Person implements IFieldValue{
name: string;
value: string;
constructor (name: string, value: string) {
this.name = name;
this.value = value;
}
}
Recently, I came across an interesting post that inspired me to refactor the implementation:
class Person implements IFieldValue{
constructor(public name: string, public value: string) {
}
}
My question pertains to the default access modifiers in TypeScript - in the first implementation, the fields are implicitly set as private
, while in the refactored version they are automatically set as public
. Am I correct in assuming this understanding?