const fullNameMaxLength = 10;
class Employee {
private _fullName: string;
set fullName(newName: string) {
if (newName && newName.length > fullNameMaxLength) {
throw new Error("fullName has a max length of " + fullNameMaxLength);
}
this._fullName = newName;
}
}
if (newName && newName.length > fullNameMaxLength)
I can understand to check that newName is truthy or not in vanillaJS but, in Typescript what is the purpose of that? Typescript already guarantees that newName is string and it has .length property.
full code is here: https://www.typescriptlang.org/docs/handbook/classes.html