question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AoT] Partial type in service constructor not resolved

See original GitHub issue

Type of Issue

[ X ] Bug Report
[ ] Feature Request

Description

Inkection tokens for configuring some services should provide some values which will override default ones. That’s what Partial type does - set each of class property as not required. Angular services works and builds well with this behavior, but libraries are not.

How To Reproduce

Here’s a project built using default commands with updated to Angular 7.2 dependencies and Partial in library constructor. Clone it and run npm run build:lib. The error you will get:

BUILD ERROR D:/Soft/OSPanel/node/angular/partial-error-setup/projects/test-lib/src/lib/test-lib.service.ts:10:1: Error encountered in metadata generated for exported symbol ‘TestLibService’: D:/Soft/OSPanel/node/angular/partial-error-setup/projects/test-lib/src/lib/test-lib.service.ts:16:33: Metadata collected contains an error that will be reported at runtime: Could not resolve type Partial. {“__symbolic”:“error”,“message”:“Could not resolve type”,“line”:15,“character”:32,“context”:{“typeName”:“Partial”}}

Expected Behaviour

Regular build without error.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr:            4.6.0
@angular/compiler:     7.2.0
rollup:                0.67.4
tsickle:               0.34.0
typescript:            3.2.2
node: 10.13.0
npm/yarn: 6.4.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
ImJohnDoecommented, Jun 1, 2019

I’m facing this issue too.

I’m building out a library of components to be shared across multiple projects. In the past, these components were embedded in a particular project. But now, we want to share them via an npm package built through an angular cli library. The components take some optional overrides from outside.

export interface IndicatorConfig {
...
}

export const INDICATOR_CONFIG = new InjectionToken<Partial<IndicatorConfig>>('my-indicator.indicator-config');

@Injectable({
  providedIn: 'root'
})
export class MyIndicatorService {
  constructor(
    @Optional()
    @Inject(INDICATOR_CONFIG)
    private configOverrides: Partial<IndicatorConfig>,
  ) {}
...
}

I imagine this is a desirable use case. Is it intentionally not supported?

0reactions
alan-agius4commented, Dec 21, 2022

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught (in promise): Error: Angular JIT compilation failed
Having a non-module in the tsconfig causes the JIT and AOT compilers to fail on serve or build. Before: { "extends": "./tsconfig.base.json", " ......
Read more >
Angular compiler options
When false , constructor parameters of classes marked with @Injectable whose type cannot be resolved produce a warning. The recommended value is true...
Read more >
How can I fix the error: System.NullReferenceException
How can I fix the error: System.NullReferenceException: 'Object reference not set to an instance of an object.' The following is my code:.
Read more >
Autofac Documentation - Read the Docs
10.1.2 None of the constructors found can be invoked . ... However, if you want BOTH services (not as common). // you can...
Read more >
Should my classes have separate constructors just for unit ...
That way you can write tests for how your class behaves if the file ... No. The question was about unit tests, which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found