zod icon indicating copy to clipboard operation
zod copied to clipboard

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

Open latobibor opened this issue 11 months ago • 8 comments

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.

latobibor avatar Mar 08 '24 23:03 latobibor

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

import { z } from "zod";

JacobWeisenburger avatar Mar 09 '24 17:03 JacobWeisenburger

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.

latobibor avatar Mar 11 '24 20:03 latobibor

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

JacobWeisenburger avatar Mar 11 '24 20:03 JacobWeisenburger

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.

colinhacks avatar Mar 13 '24 02:03 colinhacks

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

vs-jdefting avatar May 17 '24 19:05 vs-jdefting

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

IsaacAbrahamson avatar Jun 05 '24 15:06 IsaacAbrahamson

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

Matthiasvanderhallen avatar Jun 10 '24 14:06 Matthiasvanderhallen

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.

latobibor avatar Jun 12 '24 20:06 latobibor