Hello Luca,
first of all, thank you for maintaining codice-fiscale-js.
I found a possible issue/inconsistency between the TypeScript definitions and the runtime exports when using the library with modern bundlers (Angular 22 + Vite/esbuild).
Version
codice-fiscale-js 2.4.0
Angular 22
TypeScript 5.x
Expected behavior
According to the TypeScript definitions (types/codice-fiscale.d.ts), the library exposes a default export:
declare class CodiceFiscale {
static check(codiceFiscale: string): boolean;
...
}
export default CodiceFiscale;
Therefore the following code should work:
import CodiceFiscale from 'codice-fiscale-js';
CodiceFiscale.check('RSSMRA80A01H501U');
Actual behavior
At runtime the default import resolves to:
{
CodiceFiscale: [Function]
}
For example:
import CodiceFiscale from 'codice-fiscale-js';
console.log(CodiceFiscale);
console.log(typeof CodiceFiscale);
console.log(Object.keys(CodiceFiscale as any));
Output:
{ CodiceFiscale: ƒ }
object
["CodiceFiscale"]
Calling:
CodiceFiscale.check(...)
throws:
TypeError: CodiceFiscale.check is not a function
The only working solution is:
import CodiceFiscale from 'codice-fiscale-js';
const CF = (CodiceFiscale as any).CodiceFiscale;
CF.check('RSSMRA80A01H501U');
Possible cause
It looks like the TypeScript declarations expose a default export, while the runtime bundle (dist/codice.fiscale.commonjs2.js) exports an object containing a CodiceFiscale property.
This may cause interoperability issues with modern ESM-based toolchains (Angular 22, Vite, esbuild).
Could you please confirm whether this is the intended behavior or if the exports should be aligned with the TypeScript definitions?
Thank you for your work and for any clarification.
Best regards,
Federico
Hello Luca,
first of all, thank you for maintaining codice-fiscale-js.
I found a possible issue/inconsistency between the TypeScript definitions and the runtime exports when using the library with modern bundlers (Angular 22 + Vite/esbuild).
Version
codice-fiscale-js 2.4.0
Angular 22
TypeScript 5.x
Expected behavior
According to the TypeScript definitions (types/codice-fiscale.d.ts), the library exposes a default export:
declare class CodiceFiscale {
static check(codiceFiscale: string): boolean;
...
}
export default CodiceFiscale;
Therefore the following code should work:
import CodiceFiscale from 'codice-fiscale-js';
CodiceFiscale.check('RSSMRA80A01H501U');
Actual behavior
At runtime the default import resolves to:
{
CodiceFiscale: [Function]
}
For example:
import CodiceFiscale from 'codice-fiscale-js';
console.log(CodiceFiscale);
console.log(typeof CodiceFiscale);
console.log(Object.keys(CodiceFiscale as any));
Output:
{ CodiceFiscale: ƒ }
object
["CodiceFiscale"]
Calling:
CodiceFiscale.check(...)
throws:
TypeError: CodiceFiscale.check is not a function
The only working solution is:
import CodiceFiscale from 'codice-fiscale-js';
const CF = (CodiceFiscale as any).CodiceFiscale;
CF.check('RSSMRA80A01H501U');
Possible cause
It looks like the TypeScript declarations expose a default export, while the runtime bundle (dist/codice.fiscale.commonjs2.js) exports an object containing a CodiceFiscale property.
This may cause interoperability issues with modern ESM-based toolchains (Angular 22, Vite, esbuild).
Could you please confirm whether this is the intended behavior or if the exports should be aligned with the TypeScript definitions?
Thank you for your work and for any clarification.
Best regards,
Federico