In my system, I have a specific interface that outlines the structure of a NoSQL document schema. This includes strings, arrays, nested objects, and more. Here's an example representation:
interface IStudentSchema {
name: string;
age: string;
foo: {
a: number;
b: [number, number];
c: string;
}
}
I am looking to create another interface that mirrors this same structure, but replaces each value type with a designated interface (excluding object types). Here's how I envision it should look like below. It should still preserve the original type and use it as a generic.
interface IStudentSchemaFieldInfo {
name: ISchemaField<string>;
age: ISchemaField<string>;
foo: {
a: ISchemaField<number>;
b: ISchemaField<[number, number]>;
c: ISchemaField<string>;
}
}
I'm seeking a way to receive a compile-time warning if there are any modifications made to the original schema interface. Thus far, I've had to ensure they match manually.
While I can achieve this for non-nested objects using
Record<keyof IStudentSchema, ISchemaField>
, I still struggle with specifying generics for the ISchemaField
interface. Any suggestions on how to tackle this?