Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of angular components

Can I refer to angular component class as a type? I see Ionic uses any for components. Is it possible in Typescript to declare an argument type, that expects only component classes?

I saw this question, but components don't have anything in common in constructors: Passing class as parameter causes "is not newable" error

like image 834
Ebuall Avatar asked Sep 02 '25 04:09

Ebuall


2 Answers

There is ComponentType<T>. Maybe it will help.

import { ComponentType } from '@angular/cdk/overlay'; 
like image 51
Olexandr Polishchuk Avatar answered Sep 05 '25 01:09

Olexandr Polishchuk


As it turns out this is not possible in TypeScript right now. Decorators cannot change type of a class, that means they are invisible for a type system.
More info can be found here:

  • https://github.com/Microsoft/TypeScript/issues/26347
  • https://github.com/Microsoft/TypeScript/issues/4881
like image 33
Ebuall Avatar answered Sep 05 '25 00:09

Ebuall