I'm looking to define the shape of an object in TypeScript, but I want to disregard the specific types of its fields.
interface TestInterface {
TestOne?: string;
TestTwo?: number;
TestThree?: boolean;
}
My approach was to define it like this:
type Shape = { [fieldName: string]: any };
type ShapeType<TShape extends Shape> = TShape;
var test: ShapeType<TestInterface> = {
TestThree: "asdf",
}
This should raise a concern if done as follows:
var test: ShapeType<TestInterface> = {
TestThree: "asdf",
TestFour: "123",
}
If I cast "asdf" to any, it works. Is there another way to define this without needing casting?
Edit: The intention is to have a shape mainly used for data exchange, but occasionally utilized for metadata. In such instances, only the structure matters, not the type (at least for now - eventually, the plan is to convert the shape's types to another specified type).