NestJS 在构建应用程序时 fastify swagger 错误
NestJS fastify swagger errors while building app
我正在使用 fastify adapter
根据the documentation,我已经为 fastify 安装了 swagger 适配器
npm install --save @nestjs/swagger fastify-swagger
当我导入 swagger 对象时
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
在构建应用程序阶段出现多个错误:
node_modules/@nestjs/swagger/dist/decorators/api-body.decorator.d.ts:4:35 - error TS2304: Cannot find name 'Omit'.
4 declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-header.decorator.d.ts:3:43 - error TS2304: Cannot find name 'Omit'.
3 export interface ApiHeaderOptions extends Omit<ParameterObject, 'in'> {
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-param.decorator.d.ts:4:33 - error TS2304: Cannot find name 'Omit'.
4 declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-property.decorator.d.ts:2:45 - error TS2304: Cannot find name 'Omit'.
2 export interface ApiPropertyOptions extends Omit<SchemaObjectMetadata, 'name' | 'enum'> {
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-property.decorator.d.ts:8:80 - error TS2344: Type '"type" | "enum" | "example" | "format" | "deprecated"' does not satisfy the constraint '"name" | "enum"'.
Type '"type"' is not assignable to type '"name" | "enum"'.
8 export declare function ApiResponseProperty(options?: Pick<ApiPropertyOptions, 'type' | 'example' | 'format' | 'enum' | 'deprecated'>): PropertyDecorator;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@nestjs/swagger/dist/decorators/api-query.decorator.d.ts:4:33 - error TS2304: Cannot find name 'Omit'.
4 declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-response.decorator.d.ts:3:46 - error TS2304: Cannot find name 'Omit'.
3 export interface ApiResponseMetadata extends Omit<ResponseObject, 'description'> {
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-response.decorator.d.ts:9:48 - error TS2304: Cannot find name 'Omit'.
9 export interface ApiResponseSchemaHost extends Omit<ResponseObject, 'description'> {
~~~~
node_modules/@nestjs/swagger/dist/document-builder.d.ts:20:14 - error TS2304: Cannot find name 'Omit'.
20 build(): Omit<OpenAPIObject, 'components' | 'paths'>;
~~~~
node_modules/@nestjs/swagger/dist/interfaces/schema-object-metadata.interface.d.ts:3:47 - error TS2304: Cannot find name 'Omit'.
~~~~
有人知道该怎么做吗?
好的,我找到答案了
打开文件 tsconfig.json
并添加此行:
{
compilerOptions: {
"skipLibCheck": true
}
}
我不确定,这是最好的方法,因为它会在编译时跳过 node_modules 检查。但是要启动,它会有所帮助。
我正在使用 fastify adapter
根据the documentation,我已经为 fastify 安装了 swagger 适配器
npm install --save @nestjs/swagger fastify-swagger
当我导入 swagger 对象时
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
在构建应用程序阶段出现多个错误:
node_modules/@nestjs/swagger/dist/decorators/api-body.decorator.d.ts:4:35 - error TS2304: Cannot find name 'Omit'.
4 declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-header.decorator.d.ts:3:43 - error TS2304: Cannot find name 'Omit'.
3 export interface ApiHeaderOptions extends Omit<ParameterObject, 'in'> {
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-param.decorator.d.ts:4:33 - error TS2304: Cannot find name 'Omit'.
4 declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-property.decorator.d.ts:2:45 - error TS2304: Cannot find name 'Omit'.
2 export interface ApiPropertyOptions extends Omit<SchemaObjectMetadata, 'name' | 'enum'> {
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-property.decorator.d.ts:8:80 - error TS2344: Type '"type" | "enum" | "example" | "format" | "deprecated"' does not satisfy the constraint '"name" | "enum"'.
Type '"type"' is not assignable to type '"name" | "enum"'.
8 export declare function ApiResponseProperty(options?: Pick<ApiPropertyOptions, 'type' | 'example' | 'format' | 'enum' | 'deprecated'>): PropertyDecorator;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@nestjs/swagger/dist/decorators/api-query.decorator.d.ts:4:33 - error TS2304: Cannot find name 'Omit'.
4 declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-response.decorator.d.ts:3:46 - error TS2304: Cannot find name 'Omit'.
3 export interface ApiResponseMetadata extends Omit<ResponseObject, 'description'> {
~~~~
node_modules/@nestjs/swagger/dist/decorators/api-response.decorator.d.ts:9:48 - error TS2304: Cannot find name 'Omit'.
9 export interface ApiResponseSchemaHost extends Omit<ResponseObject, 'description'> {
~~~~
node_modules/@nestjs/swagger/dist/document-builder.d.ts:20:14 - error TS2304: Cannot find name 'Omit'.
20 build(): Omit<OpenAPIObject, 'components' | 'paths'>;
~~~~
node_modules/@nestjs/swagger/dist/interfaces/schema-object-metadata.interface.d.ts:3:47 - error TS2304: Cannot find name 'Omit'.
~~~~
有人知道该怎么做吗?
好的,我找到答案了
打开文件 tsconfig.json
并添加此行:
{
compilerOptions: {
"skipLibCheck": true
}
}
我不确定,这是最好的方法,因为它会在编译时跳过 node_modules 检查。但是要启动,它会有所帮助。