I want to be able to list all the properties in an interface at runtime but this doesn't look to be possible. So can I create an interface with a list of string property names?
Tried this but it doesn't work
interface MyInterface {
prop1: string;
propsList: MyProps;
}
type MyProps = "my_prop_1" | "my_prop_2"; //these types should be string
function addProps(){
const myInterface: MyInterface = {
prop1: "hello",
propsList: {
my_prop_1: "world",
my_prop_2: "hello world"
}
}
}
Trying to use the interface results in
Type {my_prop_1: string, my_prop_2: string} is not assignable to type 'MyProps'
I then want to be able to use MyProps later as a list of strings to check the properties in another list.
Is this possible?