How to extract/infer the raw value type from a Signal, Input, or Output of Angular?

Discussão em 'Angular' iniciado por Alex Pappas, Fevereiro 20, 2025.

  1. Alex Pappas

    Alex Pappas Guest

    If I have something like this:

    import { Component, output } from '@angular/core';

    @Component({...})
    export class MyComponent<TResponse> {
    success= output<{message: string, response: TResponse}>;
    }


    I am currently doing a Type extraction via indexed access and conditional inference

    onSuccess(event: MyComponent['success'] extends OutputEmitterRef<infer T> ? T : never) {
    console.log(event.message);
    }


    It just looks too bloody. Is there a more friendlier approach to this? Am I missing some already available types exported by Angular?

    Continue reading...

Compartilhe esta Página