When using [key: string]
, my type will accept any key. However, I am attempting to avoid this because in certain situations, I am redefining types for properties. Take the following scenario into consideration:
interface IObject {
[K: string]: number;
}
const base: IObject = {
title: 0,
age: 3
};
type StringValue<T> = { [K in keyof T]: string }; // <-- Is there a way to remove object index?
const child: StringValue<typeof base> = {
test: "" // <-- This should not be allowed
title: '' // <-- This is acceptable
};