Sorry for the complexity, I've struggled to simplify this further. Feel free to update the question title for more specificity.
I aim to define a foundational data type structure:
type AbstractBaseTypes = {
[key: string]: {
inputTypes: Record<string, unknown>;
outputType: unknown;
}
}
This structure consists of keys, each with corresponding input data and output data types.
For example, a concrete version of this data type can be defined as:
type KnownBaseTypes = {
"text": {
inputTypes: {
label: string;
maxLength: number;
}
outputType: string;
},
"number": {
inputTypes: {
label: string;
min: number;
max: number;
},
outputType: number;
}
}
My ultimate objective is to create a map where each key has a function that takes three parameters:
- control object = details about the key and the input data defined in KnownBaseTypes
- data - a partially known record with a single known key and its value type
- callback - accepts the output type value
Here is a JavaScript implementation:
const myDataManipulationMap = {...
My typing approach involves:
Control object:
type ControlObject<T extends AbstractBaseTypes, K extends keyof T> = {...
Partially known data object:
type PartiallyKnownDataObject<T extends AbstractBaseTypes, K extends keyof T> = {...
Combining it all:
type DataGenerationMap<T extends AbstractBaseTypes> = {...
This approach almost accomplishes my goal.
The issue is that 'partially known data' is assumed to have multiple keys with the outputType, whereas I want to restrict assumptions to the data accessible by controlObject.key only.
const myMap: DataGenerationMap<KnownBaseTypes> = {...
What's the problem here?