colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
32.64k stars 1.14k forks source link

Having `undefined` as a function that can be imported is a package design issue #3313

Open latobibor opened 5 months ago

latobibor commented 5 months ago

Hi everyone,

First of all, we like zod a lot, it is an excellent tool for its job. However I feel that having an undefined function that can be imported separately (see example below) is a metaphorical rake lying in the grass that I am stepping on way too frequently. After a while my subjective opinion is that there should be no separately importable undefined variables in zod, because it just creates much confusion.

// This just happens and then 💥 
import { undefined } from 'zod';

Any postfix/prefix could fix it, in my opinion.

If it's only me who is stepping on this rake, then just close this.

JacobWeisenburger commented 5 months ago

Perhaps this will help: https://github.com/colinhacks/zod?tab=readme-ov-file#basic-usage

import { z } from "zod";
latobibor commented 5 months ago

Perhaps this will help: https://github.com/colinhacks/zod?tab=readme-ov-file#basic-usage

import { z } from "zod";

I am well aware of this usage, however the way too friendly IDEs wish to import this function and more often than not we end up importing undefined.

JacobWeisenburger commented 5 months ago

What would you like to have happen with this issue?

  1. Leave open as an enhancement request
  2. Move to discussions where we could look into workarounds for your specific use case
colinhacks commented 5 months ago

It's pretty rakey, but I've personally never seen Zod's undefined beat out the built-in in autocomplete. If this is happening for a non-trivial fraction of users, it's something that should be addressed. We'll leave it open to see if reactions start coming in.

vs-jdefting commented 3 months ago

This issue happens semi-frequently for me. My IDE will auto-import undefined. I use IntelliJ if that matters.

IsaacAbrahamson commented 2 months ago

This just happened to me using PyCharm where undefined was auto-imported from zod when typing out a if (isBoolean === undefined) condition.

Matthiasvanderhallen commented 2 months ago

Issue comes up all the time for me in intellij as well :).

latobibor commented 2 months ago

It's an IntelliJ ecosystem problem it seems. Probably they will point out that they don't want custom logic written for 1 library and you will probably point out that this only affects IntelliJ ecosystem users.