I try to define a Record like this:
<code>// imports...
export abstract class AbstractComponent<T extends string> {
abstract prop: InputSignal<T>;
}
export class TestComponent extends AbstractComponent<'test'> {
prop: InputSignal<'test'> = input('test');
}
@Component({ standalone: true, template: `` })
export class App {
component: Record<string, typeof AbstractComponent<string>> = {
'test-1': TestComponent,
};
}
</code>
<code>// imports...
export abstract class AbstractComponent<T extends string> {
abstract prop: InputSignal<T>;
}
export class TestComponent extends AbstractComponent<'test'> {
prop: InputSignal<'test'> = input('test');
}
@Component({ standalone: true, template: `` })
export class App {
component: Record<string, typeof AbstractComponent<string>> = {
'test-1': TestComponent,
};
}
</code>
// imports...
export abstract class AbstractComponent<T extends string> {
abstract prop: InputSignal<T>;
}
export class TestComponent extends AbstractComponent<'test'> {
prop: InputSignal<'test'> = input('test');
}
@Component({ standalone: true, template: `` })
export class App {
component: Record<string, typeof AbstractComponent<string>> = {
'test-1': TestComponent,
};
}
And I get this error:
<code>Type 'typeof TestComponent' is not assignable to type 'typeof AbstractComponent<string>'.
Construct signature return types 'TestComponent' and 'AbstractComponent<string>' are incompatible.
The types of 'prop[SIGNAL].transformFn' are incompatible between these types.
Type '((value: "test") => "test") | undefined' is not assignable to type '((value: string) => string) | undefined'.
Type '(value: "test") => "test"' is not assignable to type '(value: string) => string'.
Types of parameters 'value' and 'value' are incompatible.
Type 'string' is not assignable to type '"test"'.(2322)
</code>
<code>Type 'typeof TestComponent' is not assignable to type 'typeof AbstractComponent<string>'.
Construct signature return types 'TestComponent' and 'AbstractComponent<string>' are incompatible.
The types of 'prop[SIGNAL].transformFn' are incompatible between these types.
Type '((value: "test") => "test") | undefined' is not assignable to type '((value: string) => string) | undefined'.
Type '(value: "test") => "test"' is not assignable to type '(value: string) => string'.
Types of parameters 'value' and 'value' are incompatible.
Type 'string' is not assignable to type '"test"'.(2322)
</code>
Type 'typeof TestComponent' is not assignable to type 'typeof AbstractComponent<string>'.
Construct signature return types 'TestComponent' and 'AbstractComponent<string>' are incompatible.
The types of 'prop[SIGNAL].transformFn' are incompatible between these types.
Type '((value: "test") => "test") | undefined' is not assignable to type '((value: string) => string) | undefined'.
Type '(value: "test") => "test"' is not assignable to type '(value: string) => string'.
Types of parameters 'value' and 'value' are incompatible.
Type 'string' is not assignable to type '"test"'.(2322)
How do I fix the error?
StackBlitz demo