( state: S, field: keyof S | string, )
| 13 | } |
| 14 | |
| 15 | function getFieldValue<S extends Record<string, unknown>>( |
| 16 | state: S, |
| 17 | field: keyof S | string, |
| 18 | ): unknown { |
| 19 | if (typeof field !== "string") { |
| 20 | return state[field]; |
| 21 | } |
| 22 | |
| 23 | const path = parseFieldPath(field); |
| 24 | if (path.length === 0) { |
| 25 | return undefined; |
| 26 | } |
| 27 | |
| 28 | let current: unknown = state; |
| 29 | for (const segment of path) { |
| 30 | if (current === null || typeof current !== "object") { |
| 31 | return undefined; |
| 32 | } |
| 33 | current = (current as Record<string, unknown>)[segment]; |
| 34 | } |
| 35 | |
| 36 | return current; |
| 37 | } |
| 38 | |
| 39 | function setField<S extends Record<string, unknown>>( |
| 40 | prev: Readonly<S>, |
no test coverage detected