In an Angular 6 project I'm trying to use the npm package object-set-all-values-to 3.9.45
. I did the following:
1- Installed it using npm i object-set-all-values-to
✔️ OK
2- Tried to import it ❌ Error
- 1st option
import setAllValuesTo from 'object-set-all-values-to';
Could not find a declaration file for module 'object-set-all-values-to'. '<my-project-path>/node_modules/object-set-all-values-to/dist/object-set-all-values-to.cjs.js' implicitly has an 'any' type.
Try `npm install @types/object-set-all-values-to` if it exists or add a new declaration (.d.ts) file containing `declare module 'object-set-all-values-to';`
- 2nd option:
import setAllValuesTo from 'object-set-all-values-to/dist/object-set-all-values-to.esm.js';
Could not find a declaration file for module 'object-set-all-values-to'. '<my-project-path>/node_modules/object-set-all-values-to/dist/object-set-all-values-to.esm.js' implicitly has an 'any' type.
Try `npm install @types/object-set-all-values-to` if it exists or add a new declaration (.d.ts) file containing `declare module 'object-set-all-values-to/dist/object-set-all-values-to.esm.js';`
So, How can I solve this issue❔
This alternative (const setAllValuesTo = require('object-set-all-values-to');
) works but I cannot use it because of strict code-styles rules in my project.
I already tried without success what is proposed to solve similar issues in:
For example, put above the import line // @ts-ignore
and also to declare in a src/typings.d.ts
file the module:
declare module 'object-set-all-values-to' {
export default function setAllValuesTo(inputOriginal: any, valueOriginal: any): any
}
These give me the following error: object_set_all_values_to_1.default is not a function
.
Also, I tried npm install @types/object-set-all-values-to
but it seems there is not types defined for it because I get npm ERR! code E404
.
Some possibly relevant config values in tsconfig.json
are:
{
"compilerOptions": {
// ...
"lib": [
"dom",
"es2018.promise",
"es2015"
],
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"noImplicitAny": true,
// ...
}
}
I tried changing noImplicitAny
to false
and the error reported is gone but the I get the mentioned object_set_all_values_to_1.default is not a function
I reported already the issue to the package author but got no answer so far.