Skip to content

Type Alias: IsKeyValues<TypeParameter, KeyType>

IsKeyValues<TypeParameter, KeyType> = IfAny<TypeParameter, false, TypeParameter extends object ? keyof TypeParameter extends KeyType ? true : false : false>

Type utility that checks if all keys of an object type extend a given key type. Returns false for 'any' types, non-objects, or when keys don't match the constraint.

Type Parameters

TypeParameter

TypeParameter

The object type to check

KeyType

KeyType = string

The key type constraint (defaults to string)

Example

typescript
type Test1 = IsKeyValues<{ name: string; age: number }>           // true (all keys are strings)
type Test2 = IsKeyValues<{ [key: symbol]: any }>                 // false (keys are symbols)
type Test3 = IsKeyValues<{ [key: symbol]: any }, symbol>         // true (keys match symbol constraint)
type Test4 = IsKeyValues<string>                                 // false (not an object)
type Test5 = IsKeyValues<any>                                    // false (any type)

Released under the MIT License.