Интерфейс Typescript получает тип свойства от geneti c T по ключу T's Child - PullRequest
0 голосов
/ 26 апреля 2020
export const Message = {
    key: 'chat-lists-contacts',
    name: 'Message Contact',
    description: 'A contact message card',
    children: [],
};

export interface Template {
    key: string;
    name?: string;
    description?: string;
    class?: string;
    children?: Array<ComponentRef>;
}

export interface TemplateRef<T extends Template> {
    key: T['key']; // Is it possible to enforce that this be 'chat-lists-contacts'  
    children: Array<ComponentRef>;
}

// Выше я использую как.

templateRef(): TemplateRef<typeof Message> {
    return {
      key: 'd', // It doesn't validate this as invalid, should require `chat-lists-contacts`
      children: [
        {
          id: 'id,
          settings: {
            inputs: [
              {
                key: 'styles',
                value: ''
              }
            ]
          }
        },
      ]
    };
  }

Пожалуйста, смотрите встроенные комментарии; Я хочу использовать объект Message где-нибудь еще, чтобы мне не пришлось его повторно декларировать.,

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...