fastify / ajv-compiler

Build and manage the AJV instances for the fastify framework
Other
18 stars 9 forks source link

typescript build error: Cannot use namespace '_ajv' as a type. #86

Closed juanAngel closed 2 years ago

juanAngel commented 2 years ago

Prerequisites

Fastify version

4.7.0

Plugin version

3.3.1

Node.js version

v16.14.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

fedora 35

Description

when compiling a typescript project that depends on "ajv-compiler" It stops because of an error in the type definitions

node_modules/@fastify/ajv-compiler/index.d.ts:33:19 - error TS2709: Cannot use namespace '_ajv' as a type.

33 export type Ajv = _ajv;

I am using @fastify/accepts-serializer:5.1.0

the error refers to this line https://github.com/fastify/ajv-compiler/blob/9fcbe6f85a463b014da7f581dfb5417ef3bf61fe/index.d.ts#L33 And it seems to be fixed if you change it to this export type Ajv = _ajv.Ajv;

Steps to Reproduce

npm run build

Expected Behavior

No response

mcollina commented 2 years ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

juanAngel commented 2 years ago

I have done tests, and it seems that npm downloads 2 versions of ajv in my repository, v6 in an external directory. and v8 in the subdirectory of your project. To solve the problem I had to add ajv:8 as a dependency to the package.json to force that version to always be used