Skip to content

Commit a6ef06c

Browse files
committed
fix(guards): objects with index signature as additional properties
1 parent da654f7 commit a6ef06c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/parser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ function parseInterfaceProperties(
378378
? `typeof item === '${type}'`
379379
: `is${prop.typescriptType || typescriptType}(item)`
380380
}))`
381+
: name === ADDITIONAL_PROPERTIES_KEY
382+
? `Object.values(arg).every((item: unknown) => ${
383+
isPrimitiveType
384+
? `typeof item === '${type}'`
385+
: `is${typescriptType}(item)`
386+
})`
381387
: `${
382388
prop.isPrimitiveType || isPrimitiveType
383389
? `typeof arg.${prop.name || name} === '${

tests/custom/api/guards/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function isDictionary(arg: any): arg is models.Dictionary {
119119
arg != null &&
120120
typeof arg === 'object' &&
121121
// [key: string]: DictionaryItem
122-
( isDictionaryItem(arg.[key: string]) ) &&
122+
( Object.values(arg).every((item: unknown) => isDictionaryItem(item)) ) &&
123123

124124
true
125125
);
@@ -130,7 +130,7 @@ export function isDictionaryItem(arg: any): arg is models.DictionaryItem {
130130
arg != null &&
131131
typeof arg === 'object' &&
132132
// [key: string]: number
133-
( typeof arg.[key: string] === 'number' ) &&
133+
( Object.values(arg).every((item: unknown) => typeof item === 'number') ) &&
134134

135135
true
136136
);

tests/github/api/guards/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ export function isLanguages(arg: any): arg is models.Languages {
942942
arg != null &&
943943
typeof arg === 'object' &&
944944
// [key: string]: number
945-
( typeof arg.[key: string] === 'number' ) &&
945+
( Object.values(arg).every((item: unknown) => typeof item === 'number') ) &&
946946

947947
true
948948
);

0 commit comments

Comments
 (0)