Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Error with Exported Variable and Type Inference #64

Closed
stilyng94 opened this issue Aug 15, 2023 · 1 comment
Closed

Error with Exported Variable and Type Inference #64

stilyng94 opened this issue Aug 15, 2023 · 1 comment

Comments

@stilyng94
Copy link

stilyng94 commented Aug 15, 2023

Descripttion

I encountered an issue that involves TypeScript type inference and named exports. The problem arises when attempting to export a variable created via zodToOpenAPI, which leads to an error related to the ExtendedSchemaObject

Steps to Reproduce:

import { createZodDto, zodToOpenAPI } from 'nestjs-zod';
import { z } from 'nestjs-zod/z';

export const EnvConfigSchema = z.object({
  PORT: z.coerce.number().int().positive().describe('Port number'),
});

export const EnvConfigApi = zodToOpenAPI(EnvConfigSchema);

Expected Behavior:

Typescript intellisense should not scream.

Actual Behavior:

Exported variable EnvConfigApi has or is using name ExtendedSchemaObject from external module "node_modules/.pnpm/nestjs-zod@2.3.3_@nestjs+common@10.0.0_@nestjs+core@10.0.0_@nestjs+swagger@7.1.8_zod@3.22.0/node_modules/nestjs-zod/dist/index" but cannot be named.

Proposed Solution:

The interface ExtendedSchemaObject should be included in the module's exports.
This resolves the issue.

@meirkeller
Copy link

import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
import { createZodDto, zodToOpenAPI } from 'nestjs-zod';
import { z } from 'nestjs-zod/z';

export const EnvConfigSchema = z.object({
  PORT: z.coerce.number().int().positive().describe('Port number'),
});

export const EnvConfigApi: SchemaObject = zodToOpenAPI(EnvConfigSchema);

This resolves the error. However i didn't figure out yet how to use zodToOpenAPI

@risen228 risen228 closed this as completed May 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants