Skip to content

Commit 8ebae1d

Browse files
committed
fix(core): allow service with factory on abstract classes
Fixes that setting a `@Service` with a `factory` on an abstract class was resulting in a compilation error. (cherry picked from commit c72ebcb)
1 parent b099fce commit 8ebae1d

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

goldens/public-api/core/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ export interface ServiceDecorator {
18151815
<T>(options: {
18161816
autoProvided?: true;
18171817
factory: () => T;
1818-
}): <C extends Type<unknown>>(target: C) => Type<T>;
1818+
}): <C extends Type<unknown> | AbstractType<unknown>>(target: C) => C extends Type<unknown> ? Type<T> : abstract new (...args: any[]) => T;
18191819
(options?: {
18201820
autoProvided?: true;
18211821
}): TypeDecorator;

packages/core/src/di/service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Type} from '../interface/type';
9+
import {AbstractType, Type} from '../interface/type';
1010
import {makeDecorator, TypeDecorator} from '../util/decorators';
1111
import {compileService} from './jit/service';
1212

@@ -39,7 +39,9 @@ export interface ServiceDecorator {
3939
<T>(options: {
4040
autoProvided?: true;
4141
factory: () => T;
42-
}): <C extends Type<unknown>>(target: C) => Type<T>;
42+
}): <C extends Type<unknown> | AbstractType<unknown>>(
43+
target: C,
44+
) => C extends Type<unknown> ? Type<T> : abstract new (...args: any[]) => T;
4345

4446
/**
4547
* Creates a service that is automatically provided.

0 commit comments

Comments
 (0)