Is there a way to detect the parameter type of a function using the described type and create an object with the same structure, identifying the provided fields and their value types based on the description?
Here is an example:
// Define the type
type StorageData = {
prop1: boolean;
prop2: number;
prop3: string;
prop4: "static" | "dynamic";
};
type ParamsToGet = Partial<StorageData>;
type Callback<T> = (data: T) => void;
type Get = <T extends ParamsToGet>(params: T, callback: Callback<T>) => void;
declare const get: Get;
Usage:
get({ prop1: false, prop4: "static", prop2: 1}, (data) => { ... });
/*
Current typing:
data: {
snowfallColor: string; // okay
snowfallZtop: true; // unexpected, should be boolean
snowfallCount: number; // okay
}
*/
The issue lies in the incorrect detection of property value types - instead of getting booleans for certain properties, I am receiving true or false values directly.