Is there a way to access a dynamic T property within an interface in order to enhance its typing for generic functions like this:
type AnotherType<T extends {}> = T & {
prop: boolean;
prop2: string;
};
interface SpecialInterface<T> {
someProperty: AnotherType<{T["someProperty"]}>;
}
const func = <T extends SpecialInterface<T>>(prop: T) => {
const a = prop.someProperty.prop;
}
Currently, I am using the following approach which works but has any typing allowing everything on the function prop:
interface SpecialInterface<T> {
someProperty: AnotherType<{[key: string]: any}>;
}
Here is an example of the prop sent to the func:
interface IProp {
someProperty: AnotherType<{prop3: number}>
}
const prop: IProp = {
someProperty: {
prop: true,
prop2: "test",
prop3 : 5
}
}
Does anyone have any suggestions or ideas on how to improve this?