I have this code in my angular
@Input() id: string = '_id';
@Input() name: string = 'name';
@Input() items: Item<this['id'], this['name']>[] = [];
How can i create type for items based on id and name?
if id === ‘_id’ and name === ‘name’ so type for items should be
{_id: string; name: string}[]
if id === ‘identifier’ and name === ‘title’ so type for items should be
{identifier: string; title: string}[]
i have tried to use something like this:
type Item<ID extends string, Name extends string> = {
[key in ID | Name]: string;
};
@Input() items: Item<this['id'], this['name']>[] = [];
but have no result
New contributor
Arthur Hlushko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.