Skip to content

Commit fb22853

Browse files
Copilothotlong
andcommitted
fix: address code review feedback
- Simplify ExtractOptionValues to use only ReadonlyArray (supertype of Array) - Rename ambiguous 'obj' parameter to 'value' in checkPlaceholderResidue - Use Omit<ServiceObject, 'fields'> & Pick<T, 'fields'> to avoid type conflicts Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 88de57a commit fb22853

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

packages/spec/src/data/object.zod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ export const ObjectSchema = Object.assign(ObjectSchemaBase, {
378378
* });
379379
* ```
380380
*/
381-
create: <const T extends z.input<typeof ObjectSchemaBase>>(config: T): ServiceObject & Pick<T, 'fields'> => {
381+
create: <const T extends z.input<typeof ObjectSchemaBase>>(config: T): Omit<ServiceObject, 'fields'> & Pick<T, 'fields'> => {
382382
const withDefaults = {
383383
...config,
384384
label: config.label ?? snakeCaseToLabel(config.name),
385385
};
386-
return ObjectSchemaBase.parse(withDefaults) as ServiceObject & Pick<T, 'fields'>;
386+
return ObjectSchemaBase.parse(withDefaults) as Omit<ServiceObject, 'fields'> & Pick<T, 'fields'>;
387387
},
388388
});
389389

packages/spec/src/system/translation-typegen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
type ExtractOptionValues<F> =
4141
F extends { options: ReadonlyArray<infer O> }
4242
? O extends { value: infer V extends string } ? V : never
43-
: F extends { options: Array<infer O> }
44-
? O extends { value: infer V extends string } ? V : never
45-
: never;
43+
: never;
4644

4745
// ────────────────────────────────────────────────────────────────────────────
4846
// Per-Field Translation Shape

packages/spec/src/system/translation-validator.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,19 @@ export function validateTranslationCompleteness(
104104
* Recursively checks for `__TRANSLATE__` placeholder residue in values.
105105
*/
106106
function checkPlaceholderResidue(
107-
obj: unknown,
107+
value: unknown,
108108
path: string,
109109
errors: string[],
110110
): void {
111-
if (typeof obj === 'string') {
112-
if (obj.includes(TRANSLATE_PLACEHOLDER)) {
111+
if (typeof value === 'string') {
112+
if (value.includes(TRANSLATE_PLACEHOLDER)) {
113113
errors.push(`placeholder residue: ${path}`);
114114
}
115115
return;
116116
}
117-
if (obj && typeof obj === 'object') {
118-
for (const [key, value] of Object.entries(obj)) {
119-
checkPlaceholderResidue(value, path ? `${path}.${key}` : key, errors);
117+
if (value && typeof value === 'object') {
118+
for (const [key, child] of Object.entries(value)) {
119+
checkPlaceholderResidue(child, path ? `${path}.${key}` : key, errors);
120120
}
121121
}
122122
}

0 commit comments

Comments
 (0)