Solvedangular "Expression form not supported." when compiling library project with InjectionToken
✔️Accepted Answer
I am getting this in my library build and problem is in this component constructor:
constructor(
@Inject(MAT_DIALOG_DATA) public data: { widget: GridsterWidget }
) { }
when I change it to this form, build succeeeds!
constructor(
@Inject(MAT_DIALOG_DATA) public data: DialogInputData
) { }
interface DialogInputData {
widget: GridsterWidget;
}
Other Answers:
I followed your steps and I got the same error in here.
Looking at the angular internals, more specifically at: packages/core/application_tokens.ts:53
(please, see at this link)
The statement: export declare const PLATFORM_ID: InjectionToken<Object>;
shows us that the PLATFORM_ID
token is defined as Object
(with upper 'O')
However, if we take a look at the generated test-lib.component.ts:15
the statement constructor(@Inject(PLATFORM_ID) appId: object)
shows the PLATFORM_ID
token is being injected into a variable which type is object
with lower 'o', so it does not match right?
By changing object
to Object
it worked! \o/
So that seems to be a bug on the angular generator.
I tried to find at Angular CLI where does it is generated but I was not able to find (if someone knows I would be pleased to know).
Meanwhile, just change object
to Object
and it will work!
Have you a good night!
I'm submitting a...
Current behavior
When trying to build a new Angular CLI library that uses an InjectionToken, I get the following error:
Expected behavior
No error.
Minimal reproduction of the problem with instructions
Then the build error will appear.
Full error output
What is the motivation / use case for changing the behavior?
Environment