I have an old, yucky JavaScript file full of stuff that I need to make available to my Angular service, and I just cannot figure out how to do it. I'm suprised at how hard it is to find a tutorial for this. Maybe I'm just so out of the loop that I don't even know how to ask the question...
I've created a declaration file for it (let's say it's called oldstuff.d.ts
).
clarification: this is a declaration file only. The actual code lives in a different file: oldstuff.js
At the top of my Angular service, I'm importing the declaration file like this:
import './oldstuff.d';
I am not doing anything else anywhere in the application to attempt to get the declaration file included.
This import is enough to get VS Code to recognize the definitions, and all the intellisense is working as I would expect.
In fact, I can even use the Angular CLI to build the project, and it seems to build OK.
However, as soon as I try to inject this service into a constructor elsewhere in the application, the build fails with the following error:
ERROR in ./src/app/oldstuff.d.ts
Module build failed: Error: Debug Failure. False expression: Output generation failed
at Object.assert (c:\Projects\Angular\MyApp\node_modules\typescript\lib\typescript.js:3329:23)
at Object.transpileModule (c:\Projects\Angular\MyApp\node_modules\typescript\lib\typescript.js:80449:18)
at TypeScriptFileRefactor.transpile (c:\Projects\Angular\MyApp\node_modules\@ngtools\webpack\src\refactor.js:166:27)
at Promise.resolve.then.then.then.then (c:\Projects\Angular\MyApp\node_modules\@ngtools\webpack\src\loader.js:414:37)
@ ./src/app/my-app.module.ts 23:0-34
@ ./src/main.ts
@ multi ./src/main.ts
I have googled both for that specific error message, and for generic information on how to include declaration files, and I'm coming up dry.
Here are some of the things I've looked at:
Am I hitting a legit bug, or am I doing it completely wrong?
Well, this seems really dumb, but all I had to do was remove the letter 'd' from the name of the file.
So, instead of this:
//actual filename: oldstuff.d.ts
import './oldstuff.d';
I have this:
//actual filename: oldstuff.ts
import './oldstuff'
And now it builds and works at runtime as expected. I don't understand Typescript well enough to understand whether that's expected behavior or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With