Using it in Angular
exenestecnico opened this issue · 4 comments
How could I import it in typescript for an Angular project?
Although I don't know about using Angular very much, you can usually write like this with import
:
import * as param from './jquery-param';
const obj = { key1: 'value1', key2: [10, 20, 30] };
param(obj);
TL;DR: I managed to import and use it. Thanks for your work and your response.
Had to install typings from @types/jquery-param. In StackBlitz works great with just the typings and importing with import param from 'jquery-param';
.
Went ahead and installed both packages in my real project. Then had trouble importing as the compiler complained:
ERROR in src/app/shared/services/http.service.ts:4:24 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
This is because of how the typings are exported, as stated by:
index.d.ts(8, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
So I added
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
to tsconfig.json as some answers mentioned.
Now the project compiles and works great, but the VSCode's checker marks an error in the import statement.
Would you be so kind of making the package typescript compatible by providing your own typings, or by making a PR to fix @types/jquery-param?
To resolve that problem, it seems it has no choice but to make this library compatible with ES Modules.
FYI: DefinitelyTyped/DefinitelyTyped#16456
Anyway, I'll consider it.
After closing and reopening VSCode it no longer shows error in the import. It seems it only load changes to tsconfig.json on app start. In the end all that is needed is to add "esModuleInterop": true,
to tsconfig.json for the typings to work. I apologise for taking your time and thank you for your kind attention.