Currently, I have simplified interfaces that I combine to create various types:
interface MyObject {
values: {
[1]: number,
}
}
interface MyOtherObject {
values: {
[2]: number,
}
}
export type MyObjectType = MyObject & MyOtherObject & {};
As my project grows in size, I aim to develop a robust interface/type system for creating objects with multiple elements. One specific feature I require is the ability to use parameters in interfaces. Here's an example (even though it doesn't work as intended):
Is it possible to specify parameters within interfaces? For instance, I want to assign keys to object parameters. Below is an attempt at implementing this idea:
interface MyObject<index> {
values: {
[index]: number,
}
}
export type MyFirstObjectType = MyObject<1> & MyObject<2> {};
export type MySecondObjectType = MyObject<1> & MyObject<3> {};
let newObject: MyFirstObjectType = {
values: {
[1]: 5,
[2]: 3,
// [3]: 5, this should not be allowed in "MyFirstObjectType", but allowed in "MySecondObjectType"
}
}
While this might seem like a far-fetched idea, I'm putting it out there to explore potential solutions and maybe discover something new. It's entirely possible that a different approach without this functionality may be more suitable.