I currently have a function signature that looks like this:
getProperty<T extends HTMLElement>(name: keyof T): Promise<T[keyof T]>;
While developing Web Components that extend HTMLElement, I have included a property named rows
which stores values of type Row[]
.
If I make a call to this property as shown below (in a test utility):
const rows = componentWrapper.getProperty<TableComponent>('rows');
The resulting type of rows
is a union of all potential types from the keys in TableComponent. This aligns with my expectation when using keyof
for the name argument.
My goal is to ascertain the type of rows
as Row[]
by specifying the return type differently than Promise<T[keyof T]>
. How can I determine the type of the property being retrieved based on the name argument?