Type system: implement a conditional type for extracting object keys by value type

TypeScript Hard types

Task «Type system: implement a conditional type for extracting object keys by value type»

Write a function `extractKeysByValueType` that takes an object and a value type (as a string, for example `'string'` or `'number'`). The function should return an array of keys for which the value has the specified type. Use TypeScript generics and conditional types for correct type inference. If the object is empty or there are no keys with such a type, return an empty array. Using `any` is prohibited.

Input Format

First line: JSON string with an object. Second line: string with the type name ('string', 'number', 'boolean').

Output Format

A string containing an array of keys in JSON format (e.g., ["a","b"]). If there are no keys, output [].

Examples

Example 1

INPUT
{"a": 1, "b": "hello", "c": true} number
OUTPUT
["a"]

Example 2

INPUT
{"x": "foo", "y": "bar"} string
OUTPUT
["x","y"]

Example 3

INPUT
{"a": 1, "b": 2, "c": 3} boolean
OUTPUT
[]
main.ts