Use Readonly props and optional chaining/nullish coalescing
Mark component props as Readonly<> across 15 component files and simplify edit-player-character field access with optional chaining and nullish coalescing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ interface EditFields {
|
||||
}
|
||||
|
||||
function validateFields(fields: EditFields): DomainError | null {
|
||||
if (fields.name !== undefined && fields.name.trim() === "") {
|
||||
if (fields.name?.trim() === "") {
|
||||
return {
|
||||
kind: "domain-error",
|
||||
code: "invalid-name",
|
||||
@@ -81,9 +81,9 @@ function applyFields(
|
||||
): PlayerCharacter {
|
||||
return {
|
||||
id: existing.id,
|
||||
name: fields.name === undefined ? existing.name : fields.name.trim(),
|
||||
ac: fields.ac === undefined ? existing.ac : fields.ac,
|
||||
maxHp: fields.maxHp === undefined ? existing.maxHp : fields.maxHp,
|
||||
name: fields.name?.trim() ?? existing.name,
|
||||
ac: fields.ac ?? existing.ac,
|
||||
maxHp: fields.maxHp ?? existing.maxHp,
|
||||
color:
|
||||
fields.color === undefined
|
||||
? existing.color
|
||||
|
||||
Reference in New Issue
Block a user